31
#ifndef OPENCV_FLANN_ALLOCATOR_H_
32
#define OPENCV_FLANN_ALLOCATOR_H_
51T* allocate(
size_t
count = 1)
53
T* mem = (T*) ::malloc(
sizeof(T)*count);
73
const
size_t
WORDSIZE=16;
74
const
size_t
BLOCKSIZE=8192;
97
PooledAllocator(
int
blockSize = BLOCKSIZE)
99
blocksize = blockSize;
115
while
(base != NULL) {
116
prev = *((
void**) base);
126
void* allocateMemory(
int
size)
134
size = (size + (WORDSIZE - 1)) & ~(WORDSIZE - 1);
139
if
(size > remaining) {
141
wastedMemory += remaining;
144
blockSize = (size +
sizeof(
void*) + (WORDSIZE-1) > BLOCKSIZE) ?
145
size +
sizeof(
void*) + (WORDSIZE-1) : BLOCKSIZE;
148
void* m = ::malloc(blockSize);
150
fprintf(stderr,
"Failed to allocate memory.\n");
155
((
void**) m)[0] = base;
161
remaining = blockSize -
sizeof(
void*) - shift;
162
loc = ((
char*)m +
sizeof(
void*) + shift);
165
loc = (
char*)loc + size;
180
template
<
typename
T>
181
T* allocate(
size_t
count = 1)
183
T* mem = (T*) this->allocateMemory((
int)(
sizeof(T)*count));
188
PooledAllocator(
const
PooledAllocator &);
189
PooledAllocator& operator=(
const
PooledAllocator &);