Skip to content

Cross vendor aligned allocations

Mayeul d'Avezac edited this page Apr 11, 2014 · 1 revision

Not all platforms come with an aligned allocation, such as posix_memalign, and they certainly are not standard. This script attempts to find one of many aligned allocation routines. It defaults to its own if it cannot find one.

Usage requires adding bits to the cmake file:

# Adds aligned allocation
include(AlignedAlloc)

Then, in a file under cmake configure_file, add:

@ALIGNED_ALLOC_HEADER@

namespace your_project {
  //! Aligned allocation variation
  inline void* aligned_alloc(size_t _size, size_t _alignment) {
    @ALIGNED_ALLOC_VARIATION@;
  }
}