You need a custom allocator passed. You can build one over the std::allocator quite easily:
template <typename T, size_t TALIGN=16, size_t TBLOCK=8>
class aligned_allocator : public std::allocator<T>
{
public:
aligned_allocator() {}
aligned_allocator& operator=(const aligned_allocator &rhs){
std::allocator<T>::operator=(rhs);
return *this;
}
pointer allocate(size_type n, const void *hint){
pointer p = NULL;
size_t count = sizeof(T) * n;
size_t count_left = count % TBLOCK;
if( count_left != 0 )
{
count += TBLOCK - count_left;
}
if ( !hint )
{
p = reinterpret_cast<pointer>(aligned_malloc(count,TALIGN));
}else{
p = reinterpret_cast<pointer>(aligned_realloc((void*)hint,count,TALIGN));
}
return p;
}
void deallocate(pointer p, size_type n){
aligned_free(p);
}
void construct(pointer p, const T &val){
new(p) T(val);
}
void destroy(pointer p){
p->~T();
}
};
The only thing lacking here is the aligned_malloc, aligned_realloc and aligned_free. You either need to implement them yourself (shouldn't be that hard), or find versions of those on the internet (I've seen at least one in OGRE engine).