本文整理汇总了C++中allocator::deallocate方法的典型用法代码示例。如果您正苦于以下问题:C++ allocator::deallocate方法的具体用法?C++ allocator::deallocate怎么用?C++ allocator::deallocate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类allocator
的用法示例。
在下文中一共展示了allocator::deallocate方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: free
void String::free()
{
if (elements) {
std::for_each(elements, end, [this](char &c){ alloc.destroy(&c); });
alloc.deallocate(elements, end - elements);
}
}
示例2: free
void StrVec::free() {
if (elements) {
for (auto p = first_free; p != elements;) {
alloc.destroy(--p);
}
alloc.deallocate(elements, cap - elements);
}
}
示例3: release
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:
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: get_double_float_array
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: get_string
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: get_boolean_array
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: free
void String::free()
{
for(char *p = s;p < s+sz;++p)
alloc.destroy(p);
alloc.deallocate(s,sz);
}
示例9: destroy
static void destroy(T* ptr) {
alloc_.destroy(ptr);
alloc_.deallocate(ptr, 1);
}