This header provides low-overhead, cache-line-aligned buffers, exposed as std::unique_ptr<T[], Deleter> factories:
allocate_temporary_buffer<T>(N, align) constructs elements when required and cleans them up automatically.
allocate_temporary_buffer_uninitialized<T>(N, align) returns raw storage but still ensures destructors run on release.
allocate_uninitialized_buffer<T>(N, align) exposes raw storage without ever invoking constructors or destructors. - Note
- All returned unique_ptr instances are aligned to
align bytes (default 64).
◆ allocate_temporary_buffer()
template<typename T >
| auto uni20::allocate_temporary_buffer |
( |
std::size_t |
N, |
|
|
std::size_t |
align = 64 |
|
) |
| |
Allocate a temporary buffer of T[N] aligned to align.
- If
T is trivially initializable, the buffer is left uninitialized.
- Otherwise each
T is default-constructed and the deleter runs destructors before freeing. - Template Parameters
-
| T | Element type stored in the buffer. |
- Parameters
-
| N | Number of elements to allocate. |
| align | Alignment in bytes. |
- Returns
- Unique pointer owning the memory and running destructors when needed.
- Exceptions
-
| std::bad_alloc | If allocation fails. |
◆ allocate_temporary_buffer_uninitialized()
template<typename T >
| auto uni20::allocate_temporary_buffer_uninitialized |
( |
std::size_t |
N, |
|
|
std::size_t |
align = 64 |
|
) |
| |
Allocate a temporary buffer of T[N] that is always uninitialized.
The deleter destroys elements for non-trivial types, so callers must placement-new each element before use when T is not trivially copyable.
- Template Parameters
-
| T | Element type stored in the buffer. |
- Parameters
-
| N | Number of elements to allocate. |
| align | Alignment in bytes. |
- Returns
- Unique pointer owning the memory and running destructors when needed.
- Exceptions
-
| std::bad_alloc | If allocation fails. |
◆ allocate_uninitialized_buffer()
template<typename T >
| detail::aligned_buf_t< T > uni20::allocate_uninitialized_buffer |
( |
std::size_t |
N, |
|
|
std::size_t |
align = 64 |
|
) |
| |
Allocate raw, aligned storage for T[N] without running constructors or destructors.
When T is not trivially copyable you must placement-new each element before use and invoke std::destroy_n prior to releasing the buffer.
- Template Parameters
-
| T | Element type stored in the buffer. |
- Parameters
-
| N | Number of elements to allocate. |
| align | Byte alignment for the allocation (defaults to 64). |
- Returns
- Unique pointer that releases the raw storage without invoking destructors.
- Exceptions
-
| std::bad_alloc | If allocation fails. |