- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
namespace bt {
#define MEMNULL \
_FORCEINLINE void* operator new(size_t) { return 0; } \
_FORCEINLINE void operator delete(void* ) { }
#define MEMDEFAULT(classname) \
_FORCEINLINE void* operator new(size_t size) { return extFunctions.CreateMem((unsigned int)size, 0); } \
_FORCEINLINE void operator delete(void* val) { extFunctions.DeleteMem(val, 0); }
#define MEMMANAGER(classname) \
_FORCEINLINE void* operator new(size_t size) { return bt::internalmemmanager.getNew((unsigned int)size); } \
_FORCEINLINE void operator delete(void* val) {bt::internalmemmanager.freeThis(val,sizeof(classname));}
#define MEMMANAGERCLEAN(classname) \
_FORCEINLINE void* operator new(size_t size) { return bt::internalmemmanager.getNewClean((unsigned int)size); } \
_FORCEINLINE void operator delete(void* val) { bt::internalmemmanager.freeThis(val,sizeof(classname)); }
class memManagerExport {
public:
MEMDEFAULT(memManagerExport)
BT_API memManagerExport(unsigned int size);
BT_API virtual ~memManagerExport();
/// destroy all memory segments and free list of free pointers
BT_API void _free();
/// return pointer to new object and create new segment of objects if need.
BT_API void *_addAlloc();
/// return pointer to free object
BT_API void *_getFree(unsigned int size);
/// add pointer to list of free
BT_API void _appendToFree(_voidint idat);
/// mark pointer to free ???
BT_API void _markFree(void* val);
/// return number object in segment
BT_API unsigned int _valid(unsigned int id);
/// return segment number
BT_API unsigned int _segid(unsigned int id);
/// prepare calculation for object size
BT_API void _calcsize(unsigned int size);
private:
enum States {
VALIDED = 0x011F1C01,
FREE = 0
};
unsigned int fisVal;
struct p_smemManager *fargs;
};
class memManager: public memManagerExport {
public:
MEMDEFAULT(memManager)
_FORCEINLINE memManager(unsigned int size):memManagerExport(size) {}
_FORCEINLINE ~memManager() {}
/// create memory for object
_FORCEINLINE void *getNew(unsigned int size) {return (void*)_getFree(size);}
/// delete memory for object
_FORCEINLINE void freeThis(void * val) {_appendToFree((_voidint)val);}
/// destroy all memory segments and free list of free
_FORCEINLINE void free() {_free();};
};
class globalMemManager {
public:
MEMDEFAULT(globalMemManager)
}