|
|
Verweis* next; | Verweis* next; |
}; | }; |
struct Chunk { | struct Chunk { |
enum { size = 4 * 1024 }; |
enum { size = sizeof(void*) * 1024 }; |
Chunk* next; | Chunk* next; |
char mem[size]; | char mem[size]; |
}; | }; |
enum { dimension = 8 }; |
enum { dimension = 4*sizeof(void*) }; //maybe 2*sizeof(void*) was meant .. nobody knows |
Chunk* chunks[dimension]; | Chunk* chunks[dimension]; |
Verweis* head[dimension]; | Verweis* head[dimension]; |
Pool(Pool&); | Pool(Pool&); |
|
|
| |
inline void* Pool::alloc(size_t n) | inline void* Pool::alloc(size_t n) |
{ | { |
int idx = ((n + sizeof(int) - 1) / sizeof(int)) - 1; |
int idx = ((n + sizeof(void*) - 1) / sizeof(void*)) - 1; // what does that formular mean? |
if (idx >= dimension) { | if (idx >= dimension) { |
printf("panic: alloc %lu\n", n); |
printf("Using std-allocator %lu characters requested",n); |
exit(-1); |
return ::operator new(n); |
} | } |
if (head[idx] == 0) | if (head[idx] == 0) |
grow(idx); | grow(idx); |
|
|
| |
inline void Pool::free(void* b, size_t n) | inline void Pool::free(void* b, size_t n) |
{ | { |
int idx = ((n + sizeof(int) - 1) / sizeof(int)) - 1; |
int idx = ((n + sizeof(void*) - 1) / sizeof(void*)) - 1; |
if (idx >= dimension) { | if (idx >= dimension) { |
printf("panic: alloc %lu\n", n); |
printf("Using std-deallocator %lu characters to be freed",n); |
exit(-1); |
return ::operator delete(b); |
} | } |
Verweis* p = static_cast<Verweis*>(b); | Verweis* p = static_cast<Verweis*>(b); |
p->next = head[idx]; | p->next = head[idx]; |