|
|
@@ -11,7 +11,7 @@ void FixedMemoryPool__ctor(FixedMemoryPool* self, int BlockSize, int BlockCount)
|
|
|
self->data = PK_MALLOC(BlockSize * BlockCount);
|
|
|
self->data_end = self->data + BlockSize * BlockCount;
|
|
|
self->_free_list = PK_MALLOC(sizeof(void*) * BlockCount);
|
|
|
- self->_free_list_end = self->_free_list;
|
|
|
+ self->_free_list_length = BlockCount;
|
|
|
for(int i = 0; i < BlockCount; i++) {
|
|
|
self->_free_list[i] = self->data + i * BlockSize;
|
|
|
}
|
|
|
@@ -23,9 +23,9 @@ void FixedMemoryPool__dtor(FixedMemoryPool* self) {
|
|
|
}
|
|
|
|
|
|
void* FixedMemoryPool__alloc(FixedMemoryPool* self) {
|
|
|
- if(self->_free_list_end != self->_free_list) {
|
|
|
- self->_free_list_end--;
|
|
|
- return *self->_free_list_end;
|
|
|
+ if(self->_free_list_length > 0) {
|
|
|
+ self->_free_list_length--;
|
|
|
+ return self->_free_list[self->_free_list_length];
|
|
|
} else {
|
|
|
self->exceeded_bytes += self->BlockSize;
|
|
|
return PK_MALLOC(self->BlockSize);
|
|
|
@@ -35,8 +35,8 @@ void* FixedMemoryPool__alloc(FixedMemoryPool* self) {
|
|
|
void FixedMemoryPool__dealloc(FixedMemoryPool* self, void* p) {
|
|
|
bool is_valid = (char*)p >= self->data && (char*)p < self->data_end;
|
|
|
if(is_valid) {
|
|
|
- *self->_free_list_end = p;
|
|
|
- self->_free_list_end++;
|
|
|
+ self->_free_list[self->_free_list_length] = p;
|
|
|
+ self->_free_list_length++;
|
|
|
} else {
|
|
|
self->exceeded_bytes -= self->BlockSize;
|
|
|
PK_FREE(p);
|