netgen/libsrc/general/optmem.hpp

67 lines
1.1 KiB
C++
Raw Normal View History

2009-01-13 04:40:13 +05:00
#ifndef FILE_OPTMEM
#define FILE_OPTMEM
/**************************************************************************/
/* File: optmem.hh */
/* Author: Joachim Schoeberl */
/* Date: 04. Apr. 97 */
/**************************************************************************/
2009-07-20 14:36:36 +06:00
namespace netgen
{
2009-01-13 04:40:13 +05:00
/**
Optimized Memory allocation classes
*/
class BlockAllocator
{
private:
///
unsigned size, blocks;
///
void * freelist;
///
2019-07-09 13:39:16 +05:00
NgArray<char*> bablocks;
2019-07-09 03:23:09 +05:00
mutex block_allocator_mutex;
2009-01-13 04:40:13 +05:00
public:
///
BlockAllocator (unsigned asize, unsigned ablocks = 100);
///
~BlockAllocator ();
///
void * Alloc ();
/*
{
if (!freelist)
Alloc2();
void * p = freelist;
// freelist = *(void**)freelist;
freelist = *static_cast<void**> (freelist);
return p;
}
*/
///
2015-01-20 22:41:16 +05:00
void Free (void * p);
/*
2009-01-13 04:40:13 +05:00
{
2014-10-19 19:53:57 +06:00
if (!bablocks.Size()) return;
2009-01-13 04:40:13 +05:00
*(void**)p = freelist;
freelist = p;
}
2015-01-20 22:41:16 +05:00
*/
2009-01-13 04:40:13 +05:00
private:
// void Alloc2 ();
};
2009-07-20 14:36:36 +06:00
}
2009-01-13 04:40:13 +05:00
#endif