|
|
@@ -27,24 +27,6 @@
|
|
|
#include "SafePointer.h"
|
|
|
|
|
|
namespace dsr {
|
|
|
- // TODO: Implement reference counting and connect a thread-safe handle type to replace std::shared_ptr.
|
|
|
- // This should build on top of a fixed size allocator that pre-computes which recycling bin to use.
|
|
|
- // Handles could be able to contain multiple elements with the same reference counter, which is useful for giving buffers value heads in images for faster access.
|
|
|
- // TODO: Return the allocation size in UnsafeAllocation, to avoid extra calls to heap_getAllocationSize?
|
|
|
- // TODO: Create a faster and simpler allocator for things that never live past a function call or frame.
|
|
|
- // Then you just free the whole thing when done with the allocations.
|
|
|
- // Good for small images and fixed size heads, but bad for lists being reallocated many times that should recycle memory instead.
|
|
|
- // A temporary allocator can then only allocate one thing at a time or free all allocations.
|
|
|
- // A fixed size can guarantee that there is no heap allocation done at runtime.
|
|
|
- // A dynamic size can have more memory added when needed.
|
|
|
- // In debug mode, each allocation will be properly destructed.
|
|
|
- // In release mode, everything is just left as it is.
|
|
|
- // The caller allocating memory decides if the memory should be cleared or not.
|
|
|
- // A thread local version would not need any locks, but should still align with cache lines for consistency with regular heap allocations.
|
|
|
- // TODO: Allow reserving heap allocations for a specific thread to prevent accidental sharing.
|
|
|
- // This can have a separate memory pool in thread local memory to avoid using a mutex.
|
|
|
- // The thread local storage can be used for small allocations, while larger allocations can be placed among the shared memory.
|
|
|
-
|
|
|
// Allocate memory in the heap.
|
|
|
// The size argument is the minimum number of bytes to allocate, but the result may give you more than you asked for.
|
|
|
// Post-condition: Returns pointers to the payload and header.
|
|
|
@@ -55,7 +37,11 @@ namespace dsr {
|
|
|
// You may not read a single byte outside of it, because it might include padding that ends at uneven addresses.
|
|
|
// To use more memory than requested, you must round it down to whole elements.
|
|
|
// If the element's size is a power of two, you can pre-compute a bit mask using memory_createAlignmentAndMask for rounding down.
|
|
|
- uint64_t heap_getAllocationSize(uint8_t* allocation);
|
|
|
+ uint64_t heap_getAllocationSize(uint8_t const * const allocation);
|
|
|
+
|
|
|
+ // Pre-condition: The allocation pointer must point to the start of a payload allocated using heap_allocate, no offsets nor other allocators allowed.
|
|
|
+ // Post-condition: Returns a pointer to the heap allocation's header, which is used to construct safe pointers.
|
|
|
+ AllocationHeader *heap_getHeader(uint8_t const * const allocation);
|
|
|
|
|
|
// Only a pointer is needed, so that it can be sent as a function pointer to X11.
|
|
|
// TODO: Use the allocation head's alignment as the minimum alignment by combining the masks in compile time.
|
|
|
@@ -63,15 +49,7 @@ namespace dsr {
|
|
|
// No extra offsets are allowed on the pointer used to free the memory.
|
|
|
// TODO: Have a global variable containing the default memory pool.
|
|
|
// When it is destructed, all allocations that are empty will be freed and a termination flag will be enabled so that any more allocations being freed after it will free the memory themselves.
|
|
|
- void heap_free(uint8_t *allocation);
|
|
|
-
|
|
|
- /*
|
|
|
- // TODO: Apply additional safety checks when freeing the allocation using SafePointer, making sure that the correct allocation is freed.
|
|
|
- template <typename T>
|
|
|
- void heap_free(SafePointer<T> allocation) {
|
|
|
-
|
|
|
- }
|
|
|
- */
|
|
|
+ void heap_free(uint8_t * const allocation);
|
|
|
}
|
|
|
|
|
|
#endif
|