Helios Engine
A modular ECS based data-oriented C++23 game engine framework
Loading...
Searching...
No Matches
aligned_alloc.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4
5namespace helios::mem {
6
7/**
8 * @brief Allocates memory with the specified alignment.
9 * @details Uses mimalloc when enabled, `_aligned_malloc` on MSVC, and
10 * `std::aligned_alloc` on other platforms.
11 * On POSIX, `std::aligned_alloc` requires alignment >= `sizeof(void*)`.
12 * Smaller alignments are satisfied via `malloc`, which provides at least
13 * `alignof(std::max_align_t)` alignment.
14 * @warning Triggers assertion when `alignment` is zero, `alignment` is not a
15 * power of two, or `size` is zero.
16 * @param alignment The alignment in bytes (must be a power of two and non-zero)
17 * @param size The size of the memory block to allocate in bytes (must be
18 * non-zero)
19 * @param enable_profile When false, skips profiler memory events (for internal
20 * allocator backing storage that is tracked separately)
21 * @return A pointer to the allocated memory block, or `nullptr` on failure
22 */
23[[nodiscard]] void* AlignedAlloc(size_t alignment, size_t size,
24 bool enable_profile = true) noexcept;
25
26/**
27 * @brief Frees memory allocated with `AlignedAlloc`.
28 * @details Uses the allocation backend paired with `AlignedAlloc`. Passing
29 * `nullptr` is a no-op.
30 * @param ptr The pointer to the memory block to free
31 * @param enable_profile When false, skips profiler memory events
32 */
33void AlignedFree(void* ptr, bool enable_profile = true) noexcept;
34
35} // namespace helios::mem
void * AlignedAlloc(size_t alignment, size_t size, bool enable_profile=true) noexcept
Allocates memory with the specified alignment.
void AlignedFree(void *ptr, bool enable_profile=true) noexcept
Frees memory allocated with AlignedAlloc.