예제 #1
0
void String::free()
{
    if (elements) {
        std::for_each(elements, end, [this](char &c){ alloc.destroy(&c); });
        alloc.deallocate(elements, end - elements);
    }   
}
예제 #2
0
void StrVec::free() {
	if (elements) {
		for (auto p = first_free; p != elements;) {
			alloc.destroy(--p);
		}
		alloc.deallocate(elements, cap - elements);
	}
}
예제 #3
0
inline void BigNumber::release()
{//Free BigNumber space
    if(first_free){
        while(first_free != val) alloc.destroy(--first_free);
        alloc.deallocate(val,cap);
    }
    val=first_free=NULL;
    cap=len=dot=0;
}
예제 #4
0
inline BigNumber::~BigNumber()
{//Destructor
    if(val){
        for(;first_free!=val;)
            alloc.destroy(--first_free);
        alloc.deallocate(val,cap);
    }
    val=first_free=NULL;
    cap=0;
    dot=len=0;
}
예제 #5
0
core::result details::get_double_float_array(
    const char * * buffers, const std::size_t * sizes,
    std::size_t num_of_buffers,
    std::size_t & current_buffer, const char * & buffer_position,
    double * & values, std::size_t & length,
    allocator & alloc)
{
    int raw_length;
    core::result res = get_integer(buffers, sizes, num_of_buffers,
        current_buffer, buffer_position, raw_length);

    if (res == core::ok)
    {
        length = static_cast<std::size_t>(raw_length);

        double * new_array = static_cast<double *>(
            alloc.allocate(length * sizeof(double)));
        if (new_array != NULL)
        {
            values = new_array;

            for (std::size_t i = 0; res == core::ok && i != length; ++i)
            {
                res = get_double_float(buffers, sizes, num_of_buffers,
                    current_buffer, buffer_position, values[i]);
            }

            if (res != core::ok)
            {
                alloc.deallocate(new_array);
            }
        }
        else
        {
            res = core::no_memory;
        }
    }

    return res;
}
예제 #6
0
core::result details::get_string(const char * * buffers,
    const std::size_t * sizes,
    std::size_t num_of_buffers,
    std::size_t & current_buffer, const char * & buffer_position,
    const char * & value, std::size_t & length,
    allocator & alloc)
{
    int raw_length;
    core::result res = get_integer(buffers, sizes, num_of_buffers,
        current_buffer, buffer_position, raw_length);

    if (res == core::ok)
    {
        length = static_cast<std::size_t>(raw_length);

        char * new_buffer =
            static_cast<char *>(alloc.allocate(length));
        if (new_buffer != NULL)
        {
            value = new_buffer;

            res = get_raw_string(buffers, sizes, num_of_buffers,
                current_buffer, buffer_position,
                new_buffer, length);

            if (res != core::ok)
            {
                alloc.deallocate(new_buffer);
            }
        }
        else
        {
            res = core::no_memory;
        }
    }

    return res;
}
예제 #7
0
core::result details::get_boolean_array(
    const char * * buffers, const std::size_t * sizes,
    std::size_t num_of_buffers,
    std::size_t & current_buffer, const char * & buffer_position,
    bool * & values, std::size_t & length,
    allocator & alloc)
{
    int raw_length;
    core::result res = get_integer(buffers, sizes, num_of_buffers,
        current_buffer, buffer_position, raw_length);

    if (res == core::ok)
    {
        length = static_cast<std::size_t>(raw_length);

        const std::size_t byte_length = length * sizeof(bool);
        bool * new_array = static_cast<bool *>(
            alloc.allocate(byte_length));
        if (new_array != NULL)
        {
            std::memset(new_array, 0, byte_length);

            values = new_array;

            const std::size_t full_words = length / bits_in_word;
            char word[bytes_in_word];

            // first process full words
            for (std::size_t i = 0; i != full_words; ++i)
            {
                res = get_word_preserve_order(
                    buffers, sizes, num_of_buffers,
                    current_buffer, buffer_position, word);
                if (res != core::ok)
                {
                    break;
                }

                for (std::size_t j = 0; j != bits_in_word; ++j)
                {
                    const std::size_t byte_position = j / bits_in_byte;
                    const std::size_t bit_position = j % bits_in_byte;

                    if (word[byte_position] & (1 << bit_position))
                    {
                        values[i * bits_in_word + j] = true;
                    }
                }
            }

            // tail (what could not be read as a full word)
            if (res == core::ok)
            {
                res = get_word_preserve_order(
                    buffers, sizes, num_of_buffers,
                    current_buffer, buffer_position, word);

                if (res == core::ok)
                {
                    const std::size_t already_read_bits =
                        full_words * bits_in_word;

                    for (std::size_t j = already_read_bits;
                         j != length; ++j)
                    {
                        const std::size_t byte_position =
                            (j - already_read_bits) / bits_in_byte;
                        const std::size_t bit_position = j % bits_in_byte;

                        if (word[byte_position] & (1 << bit_position))
                        {
                            values[j] = true;
                        }
                    }
                }
            }

            if (res != core::ok)
            {
                alloc.deallocate(new_array);
            }
        }
        else
        {
            res = core::no_memory;
        }
    }

    return res;
}
예제 #8
0
void String::free()
{
    for(char *p = s;p < s+sz;++p)
        alloc.destroy(p);
    alloc.deallocate(s,sz);
}
예제 #9
0
 static void destroy(T* ptr) {
     alloc_.destroy(ptr);
     alloc_.deallocate(ptr, 1);
 }