diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-02-24 17:53:46 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-25 14:36:46 +0200 |
commit | a307f17f44b461f58441926fcbf87883f17ebe61 (patch) | |
tree | ea03a634f06c33591c8afea5139e7e931d429cf7 /include/scoped_allocator.h | |
parent | 12e5135d95dc34fd7f7a7c50d6dbac453f252683 (diff) |
Fixed CHECK_RESULT macro, use scoped allocator
Scoped allocator gives us better performance and cleanup code for error
cases is much cleaner
Diffstat (limited to 'include/scoped_allocator.h')
-rw-r--r-- | include/scoped_allocator.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/include/scoped_allocator.h b/include/scoped_allocator.h new file mode 100644 index 0000000..1193439 --- /dev/null +++ b/include/scoped_allocator.h @@ -0,0 +1,27 @@ +#ifndef AMALGAM_SCOPED_ALLOCATOR_H +#define AMALGAM_SCOPED_ALLOCATOR_H + +#include "misc.h" +#include "types.h" + +typedef struct ScopedAllocatorNode ScopedAllocatorNode; + +struct ScopedAllocatorNode { + char *data; + usize size; + ScopedAllocatorNode *next; +}; + +typedef struct { + ScopedAllocatorNode head; + ScopedAllocatorNode *current; +} ScopedAllocator; + +CHECK_RESULT int scoped_allocator_node_init(ScopedAllocatorNode *self); +void scoped_allocator_node_deinit(ScopedAllocatorNode *self); + +CHECK_RESULT int scoped_allocator_init(ScopedAllocator *self); +void scoped_allocator_deinit(ScopedAllocator *self); +CHECK_RESULT int scoped_allocator_alloc(ScopedAllocator *self, usize size, void **mem); + +#endif
\ No newline at end of file |