本文整理汇总了C++中std::allocator::deallocate方法的典型用法代码示例。如果您正苦于以下问题:C++ allocator::deallocate方法的具体用法?C++ allocator::deallocate怎么用?C++ allocator::deallocate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::allocator
的用法示例。
在下文中一共展示了allocator::deallocate方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
/**
* @brief destroy the elements and deallocate the space previously allocated.
*/
void StrVec::free()
{
if (element) // if not nullptr
{
//! destory it in reverse order.
for (auto p = first_free; p != element; /* empty */)
alloc.destroy(--p);
alloc.deallocate(element, capacity());
}
}
示例3: free
void free()
{
// may not pass deallocate() a nullptr.
if (element_)
{
// move backward and use "--p" to delete [element_, free)
// call type dtor, which is string dtor.
for (auto p = free_; p != element_; /* empty */ )
alloc.destroy(--p);
alloc.deallocate(element_, cap_ - element_);
}
}
示例4: PSFastMemFree
void PSFastMemFree(void *block)
{
NL_PS_FUNC(PSFastMemFree)
uint8 *realAddress = (uint8 *) ((uint8 *) block - sizeof(CPSAllocInfo));
CPSAllocInfo *ai = (CPSAllocInfo *) realAddress;
if (ai->BlocAllocator)
{
// block comes from a block allocator
ai->BlocAllocator->free((void *) realAddress, ai->NumAllocatedBytes + sizeof(CPSAllocInfo));
}
else
{
// block comes from the stl allocator
PSStdAllocator.deallocate((uint8 *) realAddress, ai->NumAllocatedBytes + sizeof(CPSAllocInfo));
}
}
示例5: init
/**
@brief �ͷ�ԭ�ȵĿռ䲢���·���
�൱�ڰ��³ߴ����¹���һ���� AutoGrownMemIO
����Ҫ�Ѿ����ݿ������µ�ַ
*/
void AutoGrownMemIO::init(size_t newsize)
{
// if (m_beg)
// ::free(m_beg);
// m_pos = m_beg = m_end = 0;
// m_beg = (byte*)::malloc(newsize);
size_t oldSize = size();
try {
if (m_beg) {
G_byteAlloc.deallocate(m_beg, oldSize);
m_pos = m_beg = m_end = 0;
}
m_beg = G_byteAlloc.allocate(newsize);
}
catch (const std::exception& exp)
{
std::ostringstream oss;
oss << "at " << BOOST_CURRENT_FUNCTION << ": size=" << oldSize << ", newsize=" << newsize
<< ", nested-exption[, type=" << typeid(exp).name() << ", what=" << exp.what() << "]";
throw std::runtime_error(oss.str());
}
if (0 == m_beg)
{
#ifdef _MSC_VER
std::ostringstream oss;
oss << "alloc failed in \"" << BOOST_CURRENT_FUNCTION
<< "\", with capacity=" << newsize
<< ", [this=" << (void*)(this)
<< "] was partly mutated and is not in consistent state!";
throw std::bad_alloc(oss.str().c_str());
#else
throw std::bad_alloc();
#endif
}
m_pos = m_beg;
m_end = m_beg + newsize;
}
示例6: resize
/**
@brief �ı� buffer �ߴ�
���ı� buffer �е��Ѵ����ݣ����ı� pos
@note must m_pos <= newsize
*/
void AutoGrownMemIO::resize(size_t newsize)
{
assert(tell() <= newsize);
// byte* newbeg = (byte*)::realloc(m_beg, newsize);
byte* newbeg = 0;
try {
newbeg = G_byteAlloc.allocate(newsize);
}
catch (const std::exception& exp)
{
std::ostringstream oss;
oss << "at " << BOOST_CURRENT_FUNCTION << ": size=" << size() << ", newsize=" << newsize
<< ", nested-exption[, type=" << typeid(exp).name() << ", what=" << exp.what() << "]";
throw std::runtime_error(oss.str());
}
if (newbeg)
{
memcpy(newbeg, m_beg, size());
G_byteAlloc.deallocate(m_beg, size() );
m_pos = newbeg + (m_pos - m_beg);
m_beg = newbeg;
m_end = newbeg + newsize;
}
else
{
#ifdef _MSC_VER
std::ostringstream oss;
oss << "realloc failed in \"void AutoGrownMemIO::resize(newsize=" << newsize
<< ")\", the AutoGrownMemIO object is not mutated!";
throw std::bad_alloc(oss.str().c_str());
#else
throw std::bad_alloc();
#endif
}
}
示例7: size
AutoGrownMemIO::~AutoGrownMemIO()
{
// if (m_beg) ::free(m_beg);
if (m_beg)
G_byteAlloc.deallocate(m_beg, size());
}
示例8: l_free_func
static void l_free_func(void *block, int oldSize)
{
l_stlAlloc.deallocate((uint8 *) block, oldSize);
}
示例9: free
void str_vec::free()
{
for(std::string *p = first_free;p > elements;)
alloc.destroy(--p);
alloc.deallocate(elements,cap-elements);
}
示例10: free
void String::free() {
if (cStringBegin) {
std::for_each(cStringBegin, cStringEnd, [this](char &c){alloc.destroy(&c);});
alloc.deallocate(cStringBegin, cStringEnd - cStringBegin);
}
}