ccgargantua / arena-allocator Goto Github PK
View Code? Open in Web Editor NEWSuper small, simple, and C89-compliant single-header arena "allocator".
License: Apache License 2.0
Super small, simple, and C89-compliant single-header arena "allocator".
License: Apache License 2.0
There are currently no examples in example_code/ that showcase the use of the arena_expand and arena_copy functions. These would be beneficial to add.
Currently, certain functions are annotated with extern inline
. In my opinion, this doesn't really make sense, as inlining a function "inserts" the respective code directly into the call site, so it wouldn't make sense to emit their symbol in the object files.
ifdef
and static inline
themI believe this approach would be the most appropriate for the inlined functions. On top of being more technically correct as to what the compiler is doing, it also serves to document what is actually happening when using the functions (ie: the functions are being "copied" at every call site).
inline
functionsInlining these functions will not benefit performance for a vast majority of use cases. It should, therefore, be removed and users who may benefit from aggressive inlining can add the respective annotations themselves.
The current Makefile
only functions as intended on Linux, but not Windows. Here is a description of problems and potential solutions.
$ make test
, finding an alternative command line memory profiler is necessary and should be conditionally applied to Windows builds..exe
file extensions on generated executables results in failure of automated runs, also present on $ make test
. This could likely be solved with a simple macro. EXT := .exe
or something similar.$(CC)
chosen when building on Windows is cc
, which is not ideal. I would prefer MSVC
be used, or at the very least mingw
. I'm not really sure how to handle this one to be completely honest.I tested this using make
installed through the chocolatey package manager for windows.
Unaligned memory can impact performance, and thus alignment should be encouraged on allocations.
Maybe have a #define
for default alignment.
Calling arena_destroy()
after using arena_clear()
causes a double free.
Arena *arena = arena_create(1024);
arena_alloc(arena, 16);
arena_clear(arena);
arena_destroy(arena);
The arena_expand() function relies on implementation for deallocation
As for as I can tell: deallocation of the ptr
argument for realloc
(the default realloc
for ARENA_REALLOC) is not officially guaranteed until C99.
(C99, 7.20.3.4p2) "The realloc function deallocates the old object pointed to by ptr and returns a pointer to a new object that has the size specified by size."
This means memory leaks are possible depending on the implementation's decision to free existing allocations for the pointer passed to it.
The arena_alloc_aligned()
method does not align properly. This is because the offset is being calculated based on the index instead of the region pointer here
Line 116 in 72b6717
FR: Short-hand wrapper functions for memcpy
(probably ARENA_MEMCPY
) for simplified copying of an arena or an arena allocation would be nice, especially copying the arena. inline
-friendly would be ideal, which should be relatively easy considering a wrapper for memcpy
(or similar) is what should be done.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.