std::string Components::Position::toString() const { std::ostringstream ss; ss << "Components::Position[debugName = \"" << getDebugName() << "\", " << "parent = " << getParent() << "\", " << "position = " << toVector() << "]"; return ss.str(); }
bool xMemoryPool::growMemoryArray(void) { #ifdef _DEBUG std::string str("Growing memory pool: [" + getDebugName() + ":" + ToStr((unsigned long)m_chunkSize) + "] = " + ToStr((unsigned long)m_memArraySize + 1) + "\n"); ::OutputDebugStringA(str.c_str()); // the logger is not initialized during many of the initial memory pool growths, so let's just use the OS version #endif // allocate a new array size_t allocationSize = sizeof(unsigned char*) * (m_memArraySize + 1); unsigned char** ppNewMemArray = (unsigned char**)malloc(allocationSize); // make sure the allocation succeeded if (!ppNewMemArray) return false; // copy any existing memory pointers over for (unsigned int i = 0; i < m_memArraySize; ++i) { ppNewMemArray[i] = m_ppRawMemoryArray[i]; } // allocate a new block of memory ppNewMemArray[m_memArraySize] = allocateNewMemoryBlock(); // indexing m_memArraySize here is safe because we haven't incremented it yet to reflect the new size // attach the block to the end of the current memory list if (m_pHead) { unsigned char* pCurr = m_pHead; unsigned char* pNext = getNext(m_pHead); while (pNext) { pCurr = pNext; pNext = getNext(pNext); } setNext(pCurr, ppNewMemArray[m_memArraySize]); } else { m_pHead = ppNewMemArray[m_memArraySize]; } // destroy the old memory array if (m_ppRawMemoryArray) free(m_ppRawMemoryArray); // assign the new memory array and increment the size count m_ppRawMemoryArray = ppNewMemArray; ++m_memArraySize; return true; }
void TileOverlay::save( VariantMap& stream ) const { VariantList config; config.push_back( (int)_d->overlayType ); MetaDataHolder& md = MetaDataHolder::instance(); config.push_back( md.hasData( _d->overlayType ) ? Variant( md.getData( _d->overlayType ).getName() ) : Variant( getDebugName() ) ); config.push_back( getTile().getIJ() ); stream[ "config" ] = config; stream[ "picture" ] = Variant( _d->picture.getName() ); stream[ "pictureOffset" ] = _d->picture.getOffset(); stream[ "size" ] = _d->size; stream[ "isDeleted" ] = _d->isDeleted; stream[ "name" ] = Variant( _d->name ); }
void xMemoryPool::destroy(void) { // dump the state of the memory pool #ifdef _DEBUG std::string str; if (m_numAllocs != 0) str = "***(" + ToStr(m_numAllocs) + ") "; unsigned long totalNumChunks = m_numChunks * m_memArraySize; unsigned long wastedMem = (totalNumChunks - m_allocPeak) * m_chunkSize; str += "Destroying memory pool: [" + getDebugName() + ":" + ToStr((unsigned long)m_chunkSize) + "] = " + ToStr(m_allocPeak) + "/" + ToStr((unsigned long)totalNumChunks) + " (" + ToStr(wastedMem) + " bytes wasted)\n"; ::OutputDebugStringA(str.c_str()); // the logger is not initialized during many of the initial memory pool growths, so let's just use the OS version #endif // free all memory for (unsigned int i = 0; i < m_memArraySize; ++i) { free(m_ppRawMemoryArray[i]); } free(m_ppRawMemoryArray); // update member variables reset(); }