Formatting issue
This commit is contained in:
+56
-1
@@ -196,6 +196,8 @@ static void arena_test_allocator_interface(void)
|
|||||||
printf("test_4: allocated %u bytes page-aligned at %p\n", page_size, ptr);
|
printf("test_4: allocated %u bytes page-aligned at %p\n", page_size, ptr);
|
||||||
|
|
||||||
allocator_free_all(&allocator);
|
allocator_free_all(&allocator);
|
||||||
|
arena_free(&arena);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void arena_test_decommit(void)
|
static void arena_test_decommit(void)
|
||||||
@@ -251,7 +253,7 @@ void miniarena_test1(void)
|
|||||||
Assert(arena.first_free == 0);
|
Assert(arena.first_free == 0);
|
||||||
U32 *val = marena_push_type(&arena, U32);
|
U32 *val = marena_push_type(&arena, U32);
|
||||||
*val = 0xa0b0c0d0;
|
*val = 0xa0b0c0d0;
|
||||||
printf("marena val %u\n", *val);
|
printf("marena val 0x%x\n", *val);
|
||||||
|
|
||||||
printf("miniarena_test1,size %u bytes first_free %u\n", arena.size, arena.first_free);
|
printf("miniarena_test1,size %u bytes first_free %u\n", arena.size, arena.first_free);
|
||||||
Assert(arena.first_free == sizeof(U32));
|
Assert(arena.first_free == sizeof(U32));
|
||||||
@@ -308,8 +310,57 @@ void apool_test(void)
|
|||||||
printf("Pooltest %u\n",p->n);
|
printf("Pooltest %u\n",p->n);
|
||||||
}
|
}
|
||||||
allocator_free_all(&allocator);
|
allocator_free_all(&allocator);
|
||||||
|
arena_free(&arena);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void apool_test_miniarena(void)
|
||||||
|
{
|
||||||
|
TRACEF("\n");
|
||||||
|
|
||||||
|
MArena arena;
|
||||||
|
U8 data[4096];
|
||||||
|
marena_init(&arena, data, sizeof data);
|
||||||
|
Allocator allocator = marena_allocator(&arena);
|
||||||
|
APool *pool = apool_create_ex(&allocator, 16, sizeof(PoolTest), alignof(PoolTest));
|
||||||
|
PoolTest *list = NULL;
|
||||||
|
for (U32 i = 0; i < U32_Max; i++) {
|
||||||
|
PoolTest *pt = apool_alloc(pool);
|
||||||
|
if (pt == NULL){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
pt->n = i;
|
||||||
|
pt->next = list;
|
||||||
|
list = pt;
|
||||||
|
}
|
||||||
|
for (PoolTest *p = list; p; p = p->next){
|
||||||
|
printf("Pooltest %u\n",p->n);
|
||||||
|
}
|
||||||
|
|
||||||
|
PoolTest *next;
|
||||||
|
U32 count = 0;
|
||||||
|
for (PoolTest *p = list; count < 7 && p; p = next){
|
||||||
|
count++;
|
||||||
|
next = p->next;
|
||||||
|
printf("Pooltest freeing %u\n",p->n);
|
||||||
|
apool_free(pool, p);
|
||||||
|
}
|
||||||
|
list = NULL;
|
||||||
|
for (U32 i = 0; i < U32_Max; i++) {
|
||||||
|
PoolTest *pt = apool_alloc(pool);
|
||||||
|
if (pt == NULL){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
pt->n = i;
|
||||||
|
pt->next = list;
|
||||||
|
list = pt;
|
||||||
|
}
|
||||||
|
for (PoolTest *p = list; p; p = p->next){
|
||||||
|
printf("Pooltest %u\n",p->n);
|
||||||
|
}
|
||||||
|
allocator_free_all(&allocator);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void apool_test_autogrow(void)
|
void apool_test_autogrow(void)
|
||||||
{
|
{
|
||||||
TRACEF("\n");
|
TRACEF("\n");
|
||||||
@@ -356,6 +407,8 @@ void apool_test_autogrow(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
allocator_free_all(&allocator);
|
allocator_free_all(&allocator);
|
||||||
|
arena_free(&arena);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
@@ -369,5 +422,7 @@ int main(int argc, char *argv[])
|
|||||||
miniarena_test1();
|
miniarena_test1();
|
||||||
apool_test();
|
apool_test();
|
||||||
apool_test_autogrow();
|
apool_test_autogrow();
|
||||||
|
apool_test_miniarena();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -34,9 +34,9 @@ static void *platform_allocator_func(Allocator *allocator, AllocOperation operat
|
|||||||
free(memory);
|
free(memory);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
case Alloc_Op_Free_All:
|
case Alloc_Op_Free_All:
|
||||||
free(memory);;
|
NotImplemented;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert(false);
|
Assert(false);
|
||||||
|
|||||||
+5
-5
@@ -3,17 +3,17 @@
|
|||||||
|
|
||||||
typedef union APoolElement APoolElement;
|
typedef union APoolElement APoolElement;
|
||||||
union APoolElement {
|
union APoolElement {
|
||||||
APoolElement *next; // offset from start to next free block (when not allocated)
|
APoolElement *next; // offset from start to next free block (when not allocated)
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct APool APool;
|
typedef struct APool APool;
|
||||||
struct APool {
|
struct APool {
|
||||||
APoolElement *free_list; // free list
|
APoolElement *free_list; // free list
|
||||||
U8 *start; // start of user buffer
|
U8 *start; // start of user buffer
|
||||||
Allocator *allocator;
|
Allocator *allocator;
|
||||||
U32 element_size; // aligned size of each block
|
U32 element_size; // aligned size of each block
|
||||||
U32 n_elements; // total number of blocks
|
U32 n_elements; // total number of blocks
|
||||||
U32 align; // alignment
|
U32 align; // alignment
|
||||||
};
|
};
|
||||||
enum {
|
enum {
|
||||||
APOOL_AUTOGROW = 0
|
APOOL_AUTOGROW = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user