Skip to content

Allocator for STL containers, which can allocate e.g. 16-byte aligned memory.

License

Notifications You must be signed in to change notification settings

hansen-audio/aligned-allocator

Repository files navigation

Aligned Allocator

CMake (Linux, macOS, Windows)

Motivation

This is an attempt to build a very lightweight allocator for STL containers like std::vector, which can allocate memory aligned. With the introduction of std::aligned_alloc in c++17 there is a cross platform solution. To date it seems as if if this is not supported yet on all platforms.

Therefore I took a look into Boost align library and "copied" the MSVS and macOS parts until std::aligned_alloc is available on these platforms as well.

This is the first attempt to build a STL compatible allocator. There are unit tests avaiable. Nevertheless, be carefull when using this allocator!!!

Using the allocator

Create a vector which holds 16-byte alligned floats for e.g. audio processing purpose.

    using vector_r16b = std::vector<float, ha::alignment::aligned_allocator<float, 16>>;
    vector_r16b values;
    values.push_back(1.f);
    ...

Links

License

Copyright 2021 Hansen Audio

Licensed under the MIT: https://mit-license.org/

About

Allocator for STL containers, which can allocate e.g. 16-byte aligned memory.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages