2001-05-23 15:26:42 +02:00
|
|
|
#ifndef INCLUDE_FB_BLK
|
|
|
|
#define INCLUDE_FB_BLK
|
|
|
|
|
2003-01-16 18:47:10 +01:00
|
|
|
#include "../common/classes/alloc.h"
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
struct blk
|
|
|
|
{
|
|
|
|
};
|
|
|
|
typedef blk* BLK;
|
|
|
|
typedef blk* BlkPtr;
|
|
|
|
|
2008-01-16 08:15:01 +01:00
|
|
|
// Traditional way to check handle type
|
|
|
|
template<SSHORT BlockType>
|
|
|
|
class PoolType : public blk
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool checkHandle() const
|
|
|
|
{
|
|
|
|
if (!this)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return MemoryPool::blk_type(this) == BlockType;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2002-12-16 22:19:51 +01:00
|
|
|
template<SSHORT BLOCK_TYPE = 0>
|
2008-01-16 08:15:01 +01:00
|
|
|
class pool_alloc : public PoolType<BLOCK_TYPE>
|
2001-12-24 03:51:06 +01:00
|
|
|
{
|
|
|
|
public:
|
2002-09-25 19:12:16 +02:00
|
|
|
#ifdef DEBUG_GDS_ALLOC
|
|
|
|
void* operator new(size_t s, MemoryPool& p, char* file, int line)
|
2003-01-16 18:47:10 +01:00
|
|
|
{ return p.calloc(s, BLOCK_TYPE, file, line); }
|
2002-09-25 19:12:16 +02:00
|
|
|
void* operator new[](size_t s, MemoryPool& p, char* file, int line)
|
2003-01-16 18:47:10 +01:00
|
|
|
{ return p.calloc(s, BLOCK_TYPE, file, line); }
|
2002-09-25 19:12:16 +02:00
|
|
|
#else
|
2001-12-24 03:51:06 +01:00
|
|
|
void* operator new(size_t s, MemoryPool& p )
|
2003-01-16 18:47:10 +01:00
|
|
|
{ return p.calloc(s, BLOCK_TYPE); }
|
2001-12-24 03:51:06 +01:00
|
|
|
void* operator new[](size_t s, MemoryPool& p)
|
2003-01-16 18:47:10 +01:00
|
|
|
{ return p.calloc(s, BLOCK_TYPE); }
|
2002-09-25 19:12:16 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void operator delete(void* mem, MemoryPool& p)
|
|
|
|
{ if (mem) p.deallocate(mem); }
|
2001-12-24 03:51:06 +01:00
|
|
|
void operator delete[](void* mem, MemoryPool& p)
|
2002-04-04 07:38:26 +02:00
|
|
|
{ if (mem) p.deallocate(mem); }
|
2001-12-24 03:51:06 +01:00
|
|
|
|
2003-01-16 18:47:10 +01:00
|
|
|
void operator delete(void* mem) { if (mem) MemoryPool::globalFree(mem); }
|
|
|
|
void operator delete[](void* mem) { if (mem) MemoryPool::globalFree(mem); }
|
2001-12-24 03:51:06 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
/* These operators are off-limits */
|
|
|
|
void* operator new(size_t s) { return 0; }
|
|
|
|
void* operator new[](size_t s) { return 0; }
|
|
|
|
};
|
|
|
|
|
2004-03-13 09:29:48 +01:00
|
|
|
template<typename RPT, SSHORT BLOCK_TYPE = 0>
|
2008-01-16 08:15:01 +01:00
|
|
|
class pool_alloc_rpt : public PoolType<BLOCK_TYPE>
|
2001-12-24 03:51:06 +01:00
|
|
|
{
|
|
|
|
public:
|
2004-03-13 09:29:48 +01:00
|
|
|
typedef RPT blk_repeat_type;
|
2002-09-25 19:12:16 +02:00
|
|
|
#ifdef DEBUG_GDS_ALLOC
|
2003-10-20 12:34:33 +02:00
|
|
|
void* operator new(size_t s, MemoryPool& p, int rpt, char* file, int line)
|
|
|
|
{ return p.calloc(s + sizeof(RPT) * rpt, BLOCK_TYPE, file, line); }
|
2002-09-25 19:12:16 +02:00
|
|
|
#else
|
2001-12-24 03:51:06 +01:00
|
|
|
void* operator new(size_t s, MemoryPool& p, int rpt)
|
2003-10-20 12:34:33 +02:00
|
|
|
{ return p.calloc(s + sizeof(RPT) * rpt, BLOCK_TYPE); }
|
2002-09-25 19:12:16 +02:00
|
|
|
#endif
|
2003-10-20 12:34:33 +02:00
|
|
|
void operator delete(void* mem, MemoryPool& p, int rpt)
|
2002-04-04 07:38:26 +02:00
|
|
|
{ if (mem) p.deallocate(mem); }
|
2003-01-16 18:47:10 +01:00
|
|
|
void operator delete(void* mem) { if (mem) MemoryPool::globalFree(mem); }
|
2001-12-24 03:51:06 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
// These operations are not supported on static repeat-base objects
|
|
|
|
void* operator new[](size_t s, MemoryPool& p)
|
|
|
|
{ return 0; }
|
|
|
|
void operator delete[](void* mem, MemoryPool& p)
|
|
|
|
{ }
|
|
|
|
void operator delete[](void* mem) { }
|
|
|
|
|
|
|
|
private:
|
|
|
|
/* These operators are off-limits */
|
|
|
|
void* operator new(size_t s) { return 0; }
|
|
|
|
void* operator new[](size_t s) { return 0; }
|
|
|
|
};
|
2001-05-23 15:26:42 +02:00
|
|
|
|
2008-01-16 08:15:01 +01:00
|
|
|
// New way to check handle type
|
|
|
|
template<SSHORT BlockType>
|
|
|
|
class LocalType
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
const SSHORT blockType;
|
|
|
|
|
|
|
|
public:
|
|
|
|
LocalType() : blockType(BlockType) { }
|
|
|
|
|
|
|
|
bool checkHandle() const
|
|
|
|
{
|
|
|
|
if (!this)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return blockType == BlockType;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2001-05-23 15:26:42 +02:00
|
|
|
#endif /* INCLUDE_FB_BLK */
|
2003-10-20 12:34:33 +02:00
|
|
|
|