attempt to fix the crash at exit, due to some threads asking for memory while the memory management structure is already gone

This commit is contained in:
csoler 2015-10-28 21:22:07 -04:00
parent 22fd4e4092
commit e56ba457fe
2 changed files with 20 additions and 5 deletions

View File

@ -158,6 +158,13 @@ void FixedAllocator::deallocate(void *p)
_chunks.pop_back();
}
}
uint32_t FixedAllocator::currentSize() const
{
uint32_t res = 0 ;
for(uint32_t i=0;i<_chunks.size();++i)
res += (_numBlocks - _chunks[i]->_blocksAvailable) * _blockSize ;
}
void FixedAllocator::printStatistics() const
{
std::cerr << " numBLocks=" << (int)_numBlocks << std::endl;
@ -181,10 +188,17 @@ SmallObjectAllocator::~SmallObjectAllocator()
{
RsStackMutex m(SmallObject::_mtx) ;
for(std::map<int,FixedAllocator*>::const_iterator it(_pool.begin());it!=_pool.end();++it)
delete it->second ;
//std::cerr << __PRETTY_FUNCTION__ << " not deleting. Leaving it to the system." << std::endl;
_active = false ;
uint32_t still_allocated = 0 ;
for(std::map<int,FixedAllocator*>::const_iterator it(_pool.begin());it!=_pool.end();++it)
still_allocated += it->second->currentSize() ;
//delete it->second ;
std::cerr << "Memory still in use at end of program: " << still_allocated << " bytes." << std::endl;
}
void *SmallObjectAllocator::allocate(size_t bytes)

View File

@ -68,8 +68,9 @@ namespace RsMemoryManagement
return p >= c._data && (static_cast<unsigned char *>(p)-c._data)/_blockSize < _numBlocks ;
}
void printStatistics() const ;
private:
void printStatistics() const ;
uint32_t currentSize() const;
private:
size_t _blockSize ;
unsigned char _numBlocks ;
std::vector<Chunk*> _chunks ;