Skip to content

Commit b793614

Browse files
committed
Fix resizing of freelist
1 parent 6dfc111 commit b793614

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Pool.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,19 @@ void* Pool_allocate(Pool* this) {
6868
}
6969
}
7070

71+
inline void* Pool_allocateClear(Pool* this) {
72+
return memset(Pool_allocate(this), 0, this->objectSize);
73+
}
74+
7175
void Pool_free(Pool* this, void* item) {
7276
if (this->destroying)
7377
return;
74-
if (this->freeListUsed < this->freeListSize) {
75-
this->freeList[this->freeListSize++] = item;
76-
} else {
78+
assert(!(this->freeListUsed > this->freeListSize));
79+
if (this->freeListUsed == this->freeListSize) {
7780
this->freeListSize += POOL_FREELIST_RATE;
7881
this->freeList = realloc(this->freeList, sizeof(void*) * this->freeListSize);
79-
this->freeList[this->freeListSize++] = item;
8082
}
83+
this->freeList[this->freeListUsed++] = item;
8184
}
8285

8386
void Pool_delete(Pool* this) {

0 commit comments

Comments
 (0)