Beispiel #1
0
void String::free()
{
    if (elements)
    {
        std::for_each(elements,end,
                    [this](char& c) {alloc.destroy(&c);});
        alloc.deallocate(elements,end-elements);
    }
}
/**
* @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());
	}
}
Beispiel #3
0
        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_);
            }
        }
Beispiel #4
0
		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));
			}
		}
Beispiel #5
0
/**
 @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;
}
Beispiel #6
0
/**
 @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
	}
}
Beispiel #7
0
AutoGrownMemIO::~AutoGrownMemIO()
{
//	if (m_beg) ::free(m_beg);
	if (m_beg)
		G_byteAlloc.deallocate(m_beg, size());
}
Beispiel #8
0
static void l_free_func(void *block, int oldSize)
{
	l_stlAlloc.deallocate((uint8 *) block, oldSize);
}
void str_vec::free()
{
    for(std::string *p = first_free;p > elements;)
        alloc.destroy(--p);
    alloc.deallocate(elements,cap-elements);
}
Beispiel #10
0
void String::free() {
    if (cStringBegin) {
        std::for_each(cStringBegin, cStringEnd, [this](char &c){alloc.destroy(&c);});
        alloc.deallocate(cStringBegin, cStringEnd - cStringBegin);
    }
}