Working on simplifying configurable allocation scheme

This commit is contained in:
Krzosa Karol
2023-01-01 12:40:58 +01:00
parent 8c0a8bf72b
commit c5539276ae
18 changed files with 169 additions and 347 deletions

View File

@@ -5,8 +5,8 @@
#define Set_BigInt_Arena(x) BigInt_Arena bigint_allocator(x)
struct BigInt_Arena{
Arena *old;
BigInt_Arena(Arena *allocator){old = bigint_allocator; bigint_allocator = allocator;}
Allocator *old;
BigInt_Arena(Allocator *allocator){old = bigint_allocator; bigint_allocator = allocator;}
~BigInt_Arena(){bigint_allocator = old;}
};
@@ -39,7 +39,7 @@ bigint_add(const BigInt *a, const BigInt *b){
}
CORE_Static BigInt
bigint_copy(Arena *allocator, BigInt *src){
bigint_copy(Allocator *allocator, BigInt *src){
BigInt dest = {};
if (src->digit_count == 0){
bigint_init_unsigned(&dest, 0);
@@ -54,7 +54,6 @@ bigint_copy(Arena *allocator, BigInt *src){
dest.is_negative = src->is_negative;
dest.digit_count = src->digit_count;
count_bigint_alloc();
dest.digits = allocate_array(allocator, uint64_t, dest.digit_count);
memcpy(dest.digits, src->digits, sizeof(uint64_t) * dest.digit_count);
return dest;
@@ -1925,7 +1924,7 @@ void bigint_print(BigInt *bigint, uint64_t base)
}
}
const char *bigint_to_error_string(Arena *allocator, const BigInt *bigint, uint64_t base)
const char *bigint_to_error_string(Allocator *allocator, const BigInt *bigint, uint64_t base)
{
Set_BigInt_Arena(allocator);
if (bigint->digit_count == 0)
@@ -1948,7 +1947,7 @@ const char *bigint_to_error_string(Arena *allocator, const BigInt *bigint, uint6
return res;
}
size_t len = bigint->digit_count * 64;
char *start = (char *)arena_push_size(allocator, len);
char *start = (char *)allocate_size(allocator, len);
char *buf = start;
BigInt digit_bi = { 0 };
@@ -1980,7 +1979,7 @@ const char *bigint_to_error_string(Arena *allocator, const BigInt *bigint, uint6
}
// reverse
char *out = (char *)arena_push_size(allocator, buf - start + 2);
char *out = (char *)allocate_size(allocator, buf - start + 2);
char *current = out;
if (bigint->is_negative)
{