refactor
remove the free function entirely. all allocators are now expected to implement reset instead. I reallized I never ever want to free an individual allocation ever again. The forever_allocator is a special case wherEreset is a no-op. The arena allocator was deleted. It will be replaced soon.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
#include "cig.h"
|
||||
|
||||
static void test_buffer_alloc(buffer_allocator_t impl) {
|
||||
allocator_t inter = buffer_allocator_interface(&impl);
|
||||
allocator_t inter = buffer_allocator(&impl);
|
||||
const int n_ints = 100;
|
||||
int *ints = allocator_alloc(inter, sizeof(int) * n_ints);
|
||||
for (int i = 0; i < n_ints; i++) {
|
||||
@@ -20,15 +20,10 @@ static void test_buffer_alloc(buffer_allocator_t impl) {
|
||||
cr_assert_eq(ints[i], i);
|
||||
}
|
||||
cr_assert_eq(impl.size, sizeof(int)*2*n_ints);
|
||||
allocator_free(inter, ints);
|
||||
size_t remaining_bytes = impl.capacity - impl.size;
|
||||
size_t double_remaining_bytes = 2 * remaining_bytes;
|
||||
void *should_be_null = allocator_resize(inter, ints, double_remaining_bytes);
|
||||
cr_assert_eq(should_be_null, NULL);
|
||||
size_t double_ints = ((size_t) n_ints) * 2;
|
||||
void *should_be_addr = allocator_resize(inter, ints, double_ints);
|
||||
cr_assert_neq(should_be_addr, NULL);
|
||||
buffer_allocator_reset(&impl);
|
||||
allocator_reset(inter);
|
||||
}
|
||||
|
||||
Test(buffer_allocator, test) {
|
||||
|
||||
Reference in New Issue
Block a user