Fixed: Arena allocator not using arena->current
This commit is contained in:
parent
f10b74763e
commit
c0a1682042
18
src/arena.c
18
src/arena.c
|
@ -46,7 +46,7 @@ arena_allocate(Arena *arena, u64 size)
|
||||||
|
|
||||||
if (current->size < pos_new && current->growable)
|
if (current->size < pos_new && current->growable)
|
||||||
{
|
{
|
||||||
Arena *new_memory_bock;
|
Arena *new_memory_block;
|
||||||
|
|
||||||
if (size > ARENA_DEFAULT_RESERVE_SIZE)
|
if (size > ARENA_DEFAULT_RESERVE_SIZE)
|
||||||
{
|
{
|
||||||
|
@ -56,17 +56,15 @@ arena_allocate(Arena *arena, u64 size)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
new_memory_bock = arena_initialize_default();
|
new_memory_block = arena_initialize_default();
|
||||||
|
|
||||||
if (new_memory_bock)
|
if (new_memory_block)
|
||||||
{
|
{
|
||||||
stack_push(arena->current, new_memory_bock, prev);
|
new_memory_block->prev = current;
|
||||||
|
*current = *new_memory_block;
|
||||||
|
|
||||||
current = new_memory_bock;
|
pos_mem = memory_align(current->offset, ARENA_DEFAULT_ALIGNMENT);
|
||||||
|
pos_new = pos_mem + size;
|
||||||
pos_mem =
|
|
||||||
memory_align(current->offset, ARENA_DEFAULT_ALIGNMENT);
|
|
||||||
pos_new = current->offset + size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -74,7 +72,7 @@ arena_allocate(Arena *arena, u64 size)
|
||||||
}
|
}
|
||||||
|
|
||||||
void *memory = (void*)((u64) current->backing_buffer + pos_mem);
|
void *memory = (void*)((u64) current->backing_buffer + pos_mem);
|
||||||
arena->offset = pos_new;
|
current->offset = pos_new;
|
||||||
|
|
||||||
platform_memory_commit(memory, size);
|
platform_memory_commit(memory, size);
|
||||||
memset(memory, 0, size);
|
memset(memory, 0, size);
|
||||||
|
|
|
@ -32,6 +32,8 @@ typedef uint64_t b64;
|
||||||
|
|
||||||
#define MIN(A,B) (((A)<(B))?(A):(B))
|
#define MIN(A,B) (((A)<(B))?(A):(B))
|
||||||
|
|
||||||
|
#define array_count(a) (sizeof(a) / sizeof((a)[0]))
|
||||||
|
|
||||||
//= rhjr: linked-list
|
//= rhjr: linked-list
|
||||||
|
|
||||||
#define check_null(p) ((p)==0)
|
#define check_null(p) ((p)==0)
|
||||||
|
|
|
@ -41,7 +41,8 @@ hash_store_string8_to_key(Table *table, String8 data)
|
||||||
node->data.length = data.length;
|
node->data.length = data.length;
|
||||||
node->key = result;
|
node->key = result;
|
||||||
|
|
||||||
memory_copy(&node->data.content, &data.content, data.length);
|
u8 *ptr = node->data.content;
|
||||||
|
memory_copy(ptr, data.content, data.length);
|
||||||
|
|
||||||
TableSlot *slot = &table->slots[slot_idx];
|
TableSlot *slot = &table->slots[slot_idx];
|
||||||
queue_push(slot->first, slot->last, node);
|
queue_push(slot->first, slot->last, node);
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
#ifndef KEYWORDS_H
|
||||||
|
#define KEYWORDS_H
|
||||||
|
|
||||||
|
internal String8 keywords[] = {
|
||||||
|
|
||||||
|
//- rhjr: testcase header
|
||||||
|
str8_lit_comp("testcase"),
|
||||||
|
str8_lit_comp("identificatiecode"),
|
||||||
|
str8_lit_comp("titel"),
|
||||||
|
str8_lit_comp("beschrijving"),
|
||||||
|
|
||||||
|
//- rhjr: testcase precond.
|
||||||
|
str8_lit_comp("precondities"),
|
||||||
|
str8_lit_comp("product configuratie"),
|
||||||
|
str8_lit_comp("toestand"),
|
||||||
|
//...
|
||||||
|
|
||||||
|
//- rhjr: testcase procedure
|
||||||
|
str8_lit_comp("testprocedure"),
|
||||||
|
|
||||||
|
//- rhjr: expected results
|
||||||
|
str8_lit_comp("luchtwasser ventilator"),
|
||||||
|
str8_lit_comp("luchtwasser waterklep"),
|
||||||
|
str8_lit_comp("luchtwasser toestand"),
|
||||||
|
str8_lit_comp("luchtwasser vultijd"),
|
||||||
|
str8_lit_comp("luchtwasser sproeiklep"),
|
||||||
|
str8_lit_comp("luchtwasser wasserpomp"),
|
||||||
|
|
||||||
|
//- rhjr: acties
|
||||||
|
str8_lit_comp("luchtwasser"),
|
||||||
|
str8_lit_comp("maximale-vlotter"),
|
||||||
|
str8_lit_comp("minimale-vlotter"),
|
||||||
|
|
||||||
|
//- rhjr: values
|
||||||
|
str8_lit_comp("wassen"),
|
||||||
|
str8_lit_comp("vullen"),
|
||||||
|
|
||||||
|
str8_lit_comp("open"),
|
||||||
|
str8_lit_comp("dicht"),
|
||||||
|
|
||||||
|
str8_lit_comp("aan"),
|
||||||
|
str8_lit_comp("uit")
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
19
src/main.c
19
src/main.c
|
@ -3,6 +3,7 @@
|
||||||
#include "arena.h"
|
#include "arena.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "hash_store.h"
|
#include "hash_store.h"
|
||||||
|
#include "keywords.h"
|
||||||
|
|
||||||
#include "win32_platform.c"
|
#include "win32_platform.c"
|
||||||
#include "arena.c"
|
#include "arena.c"
|
||||||
|
@ -13,16 +14,20 @@ int
|
||||||
main(void)
|
main(void)
|
||||||
{
|
{
|
||||||
Table *table = hash_store_initialize();
|
Table *table = hash_store_initialize();
|
||||||
|
u64 list_size = array_count(keywords);
|
||||||
|
|
||||||
String8 str8_1 = str8_lit("Hello world");
|
for (u64 idx = 0; idx < list_size; idx += 1)
|
||||||
String8 str8_2 = str8_lit("ayenooo");
|
{
|
||||||
|
if (string8_match(keywords[idx], str8_lit("luchtwasser toestand"))){
|
||||||
|
int x = 0;
|
||||||
|
}
|
||||||
|
|
||||||
Key key1 = hash_store_string8_to_key(table, str8_1);
|
Key key = hash_store_string8_to_key(table, keywords[idx]);
|
||||||
Key key2 = hash_store_string8_to_key(table, str8_2);
|
String8 string = hash_store_string8_from_key(table, key);
|
||||||
Key key3 = hash_store_string8_to_key(table, str8_1);
|
|
||||||
|
|
||||||
String8 string = hash_store_string8_from_key(table, key2);
|
printf("%.*s\n", (i32) string.length, string.content);
|
||||||
printf("%.*s\n", (i32) string.length, string.content);
|
printf("str8 arena: %lld - arena %lld\n", table->str8_arena->current->offset, table->arena->current->offset);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user