Compare commits
4 Commits
6150e5dda6
...
4be2d3b018
Author | SHA1 | Date |
---|---|---|
Eric-Paul Ickhorn | 4be2d3b018 | |
Eric-Paul Ickhorn | 15b119a372 | |
Eric-Paul Ickhorn | 5f7545ffd6 | |
Eric-Paul Ickhorn | 3fd1b69293 |
|
@ -0,0 +1,26 @@
|
|||
|
||||
# IDE/Editor - data
|
||||
.vscode/
|
||||
.eclipse/
|
||||
|
||||
# Folders that should stay local
|
||||
.private/
|
||||
.build/
|
||||
|
||||
# Executable code
|
||||
*.a
|
||||
*.dll
|
||||
*.dmg
|
||||
*.elf
|
||||
*.exe
|
||||
*.lib
|
||||
*.o
|
||||
*.out
|
||||
*.so
|
||||
|
||||
# Compiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Debug Information
|
||||
vgcore.*
|
|
@ -6,6 +6,6 @@ It currently consists of 2 independent single-header libraries
|
|||
## Functionality
|
||||
|
||||
There are only 2 libraries currently:
|
||||
1) ufn_arena: An arena allocator for optimization of string processing.
|
||||
1) ufn_arena: An arena allocator for optimizing string processing.
|
||||
2) ufn_round: Functions for rounding to the next multiple of some number
|
||||
or to the next power of 2. Currently only floor()'s and ceil()'s to those.
|
||||
|
|
|
@ -63,6 +63,7 @@ void * ufn_arena_alloc(ufn_arena_s *arena, uint32_t size);
|
|||
char * ufn_arena_clone_string(ufn_arena_s *arena, const char *string);
|
||||
|
||||
// END OF API, START OF IMPLEMENTATION.
|
||||
|
||||
#ifdef UFN_IMPLEMENTATION
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -94,13 +95,13 @@ void ufn_free_arena(ufn_arena_s *arena)
|
|||
|
||||
void * ufn_arena_alloc(ufn_arena_s *arena, uint32_t size)
|
||||
{
|
||||
if((arena->usage = size) >= arena->capacity)
|
||||
if((arena->usage + size) >= arena->capacity)
|
||||
{
|
||||
if(arena->continuation == NULL)
|
||||
{
|
||||
uint32_t continuation_size = arena->capacity * 2;
|
||||
// Clamp the continuation's size to the maximum allowed one.
|
||||
if(continuation_size > (arena->maximum))
|
||||
if(continuation_size > arena->maximum)
|
||||
{
|
||||
continuation_size = arena->maximum;
|
||||
}
|
||||
|
@ -108,7 +109,7 @@ void * ufn_arena_alloc(ufn_arena_s *arena, uint32_t size)
|
|||
// If no continuation of this arena tree can fulfill
|
||||
// a request of this size,
|
||||
// -> Deny the request and return NULL.
|
||||
if(size > arena->maximum)
|
||||
if(size >= arena->maximum)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
@ -120,7 +121,7 @@ void * ufn_arena_alloc(ufn_arena_s *arena, uint32_t size)
|
|||
}
|
||||
arena->continuation = ufn_new_dynamic_arena(continuation_size, continued_maximum);
|
||||
}
|
||||
ufn_arena_alloc(arena->continuation, size);
|
||||
return ufn_arena_alloc(arena->continuation, size);
|
||||
}
|
||||
void *block = arena->allocation + arena->usage;
|
||||
arena->usage += size;
|
||||
|
|
Loading…
Reference in New Issue