-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDS_BytePool.h
More file actions
38 lines (34 loc) · 854 Bytes
/
DS_BytePool.h
File metadata and controls
38 lines (34 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
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
#ifndef __BYTE_POOL_H
#define __BYTE_POOL_H
#include "DS_MemoryPool.h"
#include "SimpleMutex.h"
#include <assert.h>
// #define _DISABLE_BYTE_POOL
// #define _THREADSAFE_BYTE_POOL
namespace DataStructures
{
// Allocate some number of bytes from pools. Uses the heap if necessary.
class BytePool
{
public:
BytePool();
~BytePool();
// Should be at least 8 times bigger than 8192
void SetPageSize(int size);
unsigned char *Allocate(int bytesWanted);
void Release(unsigned char *data);
void Clear(void);
protected:
MemoryPool<unsigned char[128]> pool128;
MemoryPool<unsigned char[512]> pool512;
MemoryPool<unsigned char[2048]> pool2048;
MemoryPool<unsigned char[8192]> pool8192;
#ifdef _THREADSAFE_BYTE_POOL
SimpleMutex mutex128;
SimpleMutex mutex512;
SimpleMutex mutex2048;
SimpleMutex mutex8192;
#endif
};
}
#endif