Deepity
Ultra-fast, SIMD-accelerated Predictive Coding
Loading...
Searching...
No Matches
Deep::detail Namespace Reference

Functions

void * AlignedAllocPortable (size_t alignment, size_t size)
 Allocates a block of memory aligned to alignment bytes, using whichever aligned-allocation API is actually reliable on the current platform (see the comment above for why this can't just be std::aligned_alloc everywhere).
void AlignedFreePortable (void *ptr)
 Frees a block previously returned by AlignedAllocPortable().
void * HugePageAllocPortable (size_t size, bool &succeeded)
 Attempts to allocate size bytes backed by huge pages. This is genuinely opt-in and best-effort: on Linux, requests Transparent Huge Pages via madvise(MADV_HUGEPAGE) on a normal anonymous mmap – this is a HINT to the kernel, not a guarantee, and requires zero system-level configuration (unlike explicit hugetlbfs, which needs pages pre-reserved via /proc/sys/vm/nr_hugepages). On Windows, requests MEM_LARGE_PAGES via VirtualAlloc, which requires the process to hold SeLockMemoryPrivilege – NOT granted by default, so this will typically fail unless explicitly configured by an administrator.
void HugePageFreePortable (void *ptr, size_t size)
 Frees a block previously returned by HugePageAllocPortable() with succeeded=true.

Function Documentation

◆ AlignedAllocPortable()

void * Deep::detail::AlignedAllocPortable ( size_t alignment,
size_t size )
inline

Allocates a block of memory aligned to alignment bytes, using whichever aligned-allocation API is actually reliable on the current platform (see the comment above for why this can't just be std::aligned_alloc everywhere).

Parameters
alignmentRequired alignment, in bytes. Must be a valid alignment for the platform's underlying allocator (e.g. a power of two).
sizeNumber of bytes to allocate.
Returns
Pointer to the allocated block, or nullptr on failure.
Warning
The pointer returned must be freed with AlignedFreePortable(), never plain free() or delete – the underlying allocator differs by platform and the two must be paired correctly.

◆ AlignedFreePortable()

void Deep::detail::AlignedFreePortable ( void * ptr)
inline

Frees a block previously returned by AlignedAllocPortable().

Parameters
ptrPointer to free; must have been returned by AlignedAllocPortable(), not by plain malloc()/new or any other allocator.

◆ HugePageAllocPortable()

void * Deep::detail::HugePageAllocPortable ( size_t size,
bool & succeeded )
inline

Attempts to allocate size bytes backed by huge pages. This is genuinely opt-in and best-effort: on Linux, requests Transparent Huge Pages via madvise(MADV_HUGEPAGE) on a normal anonymous mmap – this is a HINT to the kernel, not a guarantee, and requires zero system-level configuration (unlike explicit hugetlbfs, which needs pages pre-reserved via /proc/sys/vm/nr_hugepages). On Windows, requests MEM_LARGE_PAGES via VirtualAlloc, which requires the process to hold SeLockMemoryPrivilege – NOT granted by default, so this will typically fail unless explicitly configured by an administrator.

Parameters
sizeNumber of bytes to allocate.
[out]succeededSet to true if huge-page-backed memory was actually obtained, false otherwise. Never throws on failure – callers should fall back to AlignedAllocPortable() when this is false.
Returns
Pointer to the allocated block if succeeded is true; nullptr otherwise.
Warning
A pointer returned here (when succeeded=true) must be freed with HugePageFree(), never AlignedFreePortable() or plain free() – the underlying allocator (mmap/VirtualAlloc) is incompatible with aligned_alloc's pairing.

◆ HugePageFreePortable()

void Deep::detail::HugePageFreePortable ( void * ptr,
size_t size )
inline

Frees a block previously returned by HugePageAllocPortable() with succeeded=true.

Parameters
ptrPointer to free.
sizeThe exact size originally passed to HugePageAllocPortable() – required on POSIX systems, where munmap() needs to know the mapping's length.