Vc  1.3.2-dev
SIMD Vector Classes for C++
Allocator< T > Class Template Reference

Detailed Description

template<typename T>
class Vc::Allocator< T >

An allocator that uses global new and supports over-aligned types, as per [C++11 20.6.9].

Meant as a simple replacement for the allocator defined in the C++ Standard. Allocation is done using the global new/delete operators. But if the alignment property of T is larger than the size of a pointer, the allocate function allocates slightly more memory to adjust the pointer for correct alignment.

If the T does not require over-alignment no additional memory will be allocated.

Template Parameters
TThe type of objects to allocate.

Example:

1 struct Data {
2  Vc::float_v x, y, z;
3 };
4 
5 void fun()
6 {
7  std::vector<Data> dat0; // this will use std::allocator<Data>, which probably ignores the
8  // alignment requirements for Data. Thus any access to dat0 may
9  // crash your program.
10 
11  std::vector<Data, Vc::Allocator<Data> > dat1; // now std::vector will get correctly aligned
12  // memory. Accesses to dat1 are safe.
13  ...

Vc ships a macro to conveniently tell STL to use Vc::Allocator per default for a given type:

1 struct Data {
2  Vc::float_v x, y, z;
3 };
4 Vc_DECLARE_ALLOCATOR(Data)
5 
6 void fun()
7 {
8  std::vector<Data> dat0; // good now
9  ...

Definition at line 128 of file Allocator.

#include <Vc/Allocator>


The documentation for this class was generated from the following file: