SLikeNet 0.1.3

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DS_BytePool.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2014, Oculus VR, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * RakNet License.txt file in the licenses directory of this source tree. An additional grant
7 * of patent rights can be found in the RakNet Patents.txt file in the same directory.
8 *
9 *
10 * Modified work: Copyright (c) 2017, SLikeSoft UG (haftungsbeschränkt)
11 *
12 * This source code was modified by SLikeSoft. Modifications are licensed under the MIT-style
13 * license found in the license.txt file in the root directory of this source tree.
14 */
15
18
19
20 #ifndef __BYTE_POOL_H
21 #define __BYTE_POOL_H
22
23 #include "memoryoverride.h"
24 #include "DS_MemoryPool.h"
25 #include "Export.h"
26 #include "SimpleMutex.h"
27 #include "assert.h"
28
29 // #define _DISABLE_BYTE_POOL
30 // #define _THREADSAFE_BYTE_POOL
31
32 namespace DataStructures
33 {
34 // Allocate some number of bytes from pools. Uses the heap if necessary.
35 class RAK_DLL_EXPORT BytePool
36 {
37 public:
38 BytePool();
39 ~BytePool();
40 // Should be at least 8 times bigger than 8192
41 void SetPageSize(int size);
42 unsigned char* Allocate(int bytesWanted, const char *file, unsigned int line);
43 void Release(unsigned char *data, const char *file, unsigned int line);
44 void Clear(const char *file, unsigned int line);
45 protected:
46 MemoryPool<unsigned char[128]> pool128;
47 MemoryPool<unsigned char[512]> pool512;
48 MemoryPool<unsigned char[2048]> pool2048;
49 MemoryPool<unsigned char[8192]> pool8192;
50 #ifdef _THREADSAFE_BYTE_POOL
51 SimpleMutex mutex128;
52 SimpleMutex mutex512;
53 SimpleMutex mutex2048;
54 SimpleMutex mutex8192;
55 #endif
56 };
57 }
58
59 #endif