Feature request: memalign allocation.
tuanhtrng opened this issue · comments
Is it possible to implement O(1) memalign?
I see two solutions immediately (there may be other, less apparent solutions):
-
Non-intrusive solution that you can implement in your application: Given a requirement of
$M$ bytes aligned at$A$ , invoke$\texttt{o1heapAllocate}\left(\text{instance}, M+A\right)$ , then bump the returned pointer to$A$ . Do not lose the original pointer as you will need it to deallocate the memory (hint: you may store the original pointer in the allocated fragment). -
Intrusive solution that requires changes to the library: redefine
O1HEAP_ALIGNMENT
. This will affect memory consumption/fragmentation for all allocations, though.
I'd like to see a solution where o1heapAllocateOveraligned(O1HeapInstance* const handle, const size_t amount, const size_t alignment)
is added to o1heap such that the user doesn't have to implement a pointer mapping scheme outside of o1heap.