A heap (in the dynamic memory sense) of memory for use in constexpr environments.
More...
template<typename VType, typename PointerInteger = uint32_t, int PointerBits = sp::bits<PointerInteger> - (std::is_unsigned_v<PointerInteger> ? 0 : 1)>
class sp::c::Heap< VType, PointerInteger, PointerBits >
A heap (in the dynamic memory sense) of memory for use in constexpr environments.
This allows you to perform dynamic memory allocation during constexpr evaluation. It is used as the basis of higher level objects like sp::c::Map
.
- Template Parameters
-
VType | The type of objects to allocate. Must be default constexpr constructible. |
PointerInteger | The integer type used to represent indices into the heap (pointer integer type). This must be a fundamental integer type. |
PointerBits | The number of bits in the pointer to use. The default is the size needed to store any non-negative value of PointerInteger. This template parameter is useful to limit the address space used by the container (e.g: to nest containers). The maximum number of simultaneously allocated objects is 2^PointerBits - 1. |
template<typename VType , typename PointerInteger = uint32_t, int PointerBits = sp::bits<PointerInteger> - (std::is_unsigned_v<PointerInteger> ? 0 : 1)>
constexpr Ptr sp::c::Heap< VType, PointerInteger, PointerBits >::allocate |
( |
| ) |
|
|
constexpr |
Allocate an object on the heap.
The object pointed to by the returned pointer will be default initialized. Pointers will be allocated starting with the first positive (non-zero) pointer integer value that is free. This means, for example, that a narrow pointer integer can be used provided there are not simultaneously too many objects allocated to uniquely reference each one with a positive pointer integer value.
- Returns
- A pointer to the allocated object.
template<typename VType , typename PointerInteger = uint32_t, int PointerBits = sp::bits<PointerInteger> - (std::is_unsigned_v<PointerInteger> ? 0 : 1)>
constexpr void sp::c::Heap< VType, PointerInteger, PointerBits >::deallocate |
( |
Ptr |
ptr | ) |
|
|
constexpr |
Deallocated a pointer previously returned by allocate().
Once this method has been called for a pointer, it must not be called again (unless allocate() subsequently returns it again). The freed object will be destroyed and default initialized.
- Parameters
-
ptr | The pointer to deallocate. This must be a pointer allocated with allocate(), and must not already be deallocated. |
template<typename VType , typename PointerInteger = uint32_t, int PointerBits = sp::bits<PointerInteger> - (std::is_unsigned_v<PointerInteger> ? 0 : 1)>
template<typename Iterable >
constexpr auto sp::c::Heap< VType, PointerInteger, PointerBits >::iteratePtrs |
( |
Iterable & |
it | ) |
|
|
constexpr |
Return an iterable object that iterates an iterable collection of IntPtrs and emits Ptrs.
This is prettymuch an evil hack until we can do more flexible constexpr memory management :D