00001 00002 00003 00004 00005 00006 00007 #ifndef __BYTE_POOL_H 00008 #define __BYTE_POOL_H 00009 00010 #include "RakMemoryOverride.h" 00011 #include "DS_MemoryPool.h" 00012 #include "Export.h" 00013 #include "SimpleMutex.h" 00014 #include "RakAssert.h" 00015 00016 // #define _DISABLE_BYTE_POOL 00017 // #define _THREADSAFE_BYTE_POOL 00018 00019 namespace DataStructures 00020 { 00021 // Allocate some number of bytes from pools. Uses the heap if necessary. 00022 class RAK_DLL_EXPORT BytePool 00023 { 00024 public: 00025 BytePool(); 00026 ~BytePool(); 00027 // Should be at least 8 times bigger than 8192 00028 void SetPageSize(int size); 00029 unsigned char* Allocate(int bytesWanted, const char *file, unsigned int line); 00030 void Release(unsigned char *data, const char *file, unsigned int line); 00031 void Clear(const char *file, unsigned int line); 00032 protected: 00033 MemoryPool<unsigned char[128]> pool128; 00034 MemoryPool<unsigned char[512]> pool512; 00035 MemoryPool<unsigned char[2048]> pool2048; 00036 MemoryPool<unsigned char[8192]> pool8192; 00037 #ifdef _THREADSAFE_BYTE_POOL 00038 SimpleMutex mutex128; 00039 SimpleMutex mutex512; 00040 SimpleMutex mutex2048; 00041 SimpleMutex mutex8192; 00042 #endif 00043 }; 00044 } 00045 00046 #endif