Migration to this repository

This commit is contained in:
Patrick Jakobsen committed 2023-09-25 12:08:27 +02:00
1 parent 3eb60da5f7
commit 6b196fc399
16 files changed
+10178

No files matched your search

+1
View File
@@ -0,0 +1 @@
gcc -std=c99 -ggdb -Wall -Wextra -fsanitize=address,undefined rdic_test.c
+51
View File
@@ -0,0 +1,51 @@
typedef struct Memory_Arena
{
void *memory;
size_t size;
size_t allocation_offset;
} Memory_Arena;
_Static_assert(sizeof(size_t) == sizeof(void*),
"The Memory_Arena implementation assumes that size_t and pointers are of the same size.");
void *memory_arena_allocate(
Memory_Arena *arena,
size_t size,
size_t alignment)
{
#if 0
printf(
"%s: arena: {.memory=%p, .size=%zu, .allocation_offset=%zu}\n"
"size: %zu, alignment: %zu\n"
, __func__
, arena->memory, arena->size, arena->allocation_offset
, size, alignment
);
#endif
size_t allocation_offset = arena->allocation_offset;
allocation_offset = ((allocation_offset + alignment - 1) / alignment) * alignment;
if(allocation_offset + size > arena->size)
{
return NULL;
}
void *allocation = ((char*)arena->memory) + allocation_offset;
arena->allocation_offset = allocation_offset + size;
return allocation;
}
void memory_arena_reset(
Memory_Arena *arena)
{
arena->allocation_offset = 0;
}
+27
View File
@@ -0,0 +1,27 @@
#include <errno.h>
#include <sys/mman.h>
// NOTE(Patrick): The memory here is by default allocated uncommitted.
// This means that we don't lock down 1GB of memory up front, but get
// allocated pages by the kernel as needed.
int linux_allocate_arena_memory(
Memory_Arena *arena,
size_t arena_size)
{
void *arena_memory = mmap(
NULL, arena_size,
PROT_READ|PROT_WRITE|PROT_EXEC, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
if(arena_memory == (void*)-1) {
//perror("mmap");
return errno;
}
arena->memory = arena_memory;
arena->size = arena_size;
return 0;
}
+1162
View File
File diff suppressed because it is too large. Load diff