1 /// \file DS_BytePool.h
2 ///
3 /// This file is part of RakNet Copyright 2003 Jenkins Software LLC
4 ///
5 /// Raknet is available under the terms of the GPLv3 license, see /usr/local/share/licenses/raknet-3.9.2_10,1/GPLv3.
6 
7 #ifndef __BYTE_POOL_H
8 #define __BYTE_POOL_H
9 
10 #include "RakMemoryOverride.h"
11 #include "DS_MemoryPool.h"
12 #include "Export.h"
13 #include "SimpleMutex.h"
14 #include "RakAssert.h"
15 
16 // #define _DISABLE_BYTE_POOL
17 // #define _THREADSAFE_BYTE_POOL
18 
19 namespace DataStructures
20 {
21 	// Allocate some number of bytes from pools.  Uses the heap if necessary.
22 	class RAK_DLL_EXPORT BytePool
23 	{
24 	public:
25 		BytePool();
26 		~BytePool();
27 		// Should be at least 8 times bigger than 8192
28 		void SetPageSize(int size);
29 		unsigned char* Allocate(int bytesWanted, const char *file, unsigned int line);
30 		void Release(unsigned char *data, const char *file, unsigned int line);
31 		void Clear(const char *file, unsigned int line);
32 	protected:
33 		MemoryPool<unsigned char[128]> pool128;
34 		MemoryPool<unsigned char[512]> pool512;
35 		MemoryPool<unsigned char[2048]> pool2048;
36 		MemoryPool<unsigned char[8192]> pool8192;
37 #ifdef _THREADSAFE_BYTE_POOL
38 		SimpleMutex mutex128;
39 		SimpleMutex mutex512;
40 		SimpleMutex mutex2048;
41 		SimpleMutex mutex8192;
42 #endif
43 	};
44 }
45 
46 #endif
47