Last active
February 4, 2017 12:19
-
-
Save amaya382/d86d3168a071b888307106f866173cd0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
using namespace std; | |
template<typename T, size_t N> | |
class aligned_allocator : public allocator<T> { | |
using size_type = typename allocator<T>::size_type; | |
using pointer = typename allocator<T>::pointer; | |
using const_pointer = typename allocator<T>::const_pointer; | |
public: | |
pointer allocate(size_type n, const_pointer = nullptr) const { | |
return reinterpret_cast<pointer>(aligned_alloc(N, n * sizeof(T))); | |
} | |
void deallocate(pointer p, size_type) const noexcept { | |
free(p); | |
} | |
}; | |
template<typename T, size_t N> | |
using aligned_vector = vector<T, aligned_allocator<T, N>>; | |
template<typename T> | |
using a32_vector = aligned_vector<T, 32>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment