当前位置: 首页>>代码示例>>C++>>正文


C++ allocator::deallocate方法代码示例

本文整理汇总了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);
    }
}
开发者ID:bowanggithub,项目名称:C-primer,代码行数:9,代码来源:ex13.44.cpp

示例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());
	}
}
开发者ID:chris918,项目名称:Cpp-Primer-5th-Edition-Answer,代码行数:15,代码来源:ex13_39_40.cpp

示例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_);
            }
        }
开发者ID:keitee,项目名称:kb,代码行数:13,代码来源:t_ex_strvec.cpp

示例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));
			}
		}
开发者ID:CCChaos,项目名称:RyzomCore,代码行数:16,代码来源:ps_allocator.cpp

示例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;
}
开发者ID:RedSunCMX,项目名称:izenelib,代码行数:44,代码来源:MemStream.cpp

示例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
	}
}
开发者ID:RedSunCMX,项目名称:izenelib,代码行数:43,代码来源:MemStream.cpp

示例7: size

AutoGrownMemIO::~AutoGrownMemIO()
{
//	if (m_beg) ::free(m_beg);
	if (m_beg)
		G_byteAlloc.deallocate(m_beg, size());
}
开发者ID:RedSunCMX,项目名称:izenelib,代码行数:6,代码来源:MemStream.cpp

示例8: l_free_func

static void l_free_func(void *block, int oldSize)
{
	l_stlAlloc.deallocate((uint8 *) block, oldSize);
}
开发者ID:mixxit,项目名称:solinia,代码行数:4,代码来源:lua_helper.cpp

示例9: free

void str_vec::free()
{
    for(std::string *p = first_free;p > elements;)
        alloc.destroy(--p);
    alloc.deallocate(elements,cap-elements);
}
开发者ID:Edward-surpass,项目名称:Cplusplusprimer5,代码行数:6,代码来源:14.26f.cpp

示例10: free

void String::free() {
    if (cStringBegin) {
        std::for_each(cStringBegin, cStringEnd, [this](char &c){alloc.destroy(&c);});
        alloc.deallocate(cStringBegin, cStringEnd - cStringBegin);
    }
}
开发者ID:Mlieou,项目名称:cpp_primer,代码行数:6,代码来源:String.hpp


注:本文中的std::allocator::deallocate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。