MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
grad::GradientAllocator< T > Class Template Reference

#include <gradient.h>

Inheritance diagram for grad::GradientAllocator< T >:
Collaboration diagram for grad::GradientAllocator< T >:

Classes

struct  rebind
 

Public Types

typedef std::allocator< T >
::pointer 
pointer
 
typedef std::allocator< T >
::size_type 
size_type
 
typedef std::allocator< T >
::difference_type 
difference_type
 
typedef std::allocator< T >
::const_pointer 
const_pointer
 
typedef std::allocator< T >
::reference 
reference
 
typedef std::allocator< T >
::const_reference 
const_reference
 
typedef std::allocator< T >
::value_type 
value_type
 

Public Member Functions

 GradientAllocator () throw ()
 
 GradientAllocator (const GradientAllocator &a) throw ()
 
template<typename U >
 GradientAllocator (const GradientAllocator< U > &a) throw ()
 
pointer allocate (size_type n, const void *p=0)
 
void deallocate (pointer p, size_type n)
 

Static Public Member Functions

static T * allocate_aligned (size_type alignment, size_t n, size_type extra_bytes=0u)
 
static void deallocate_aligned (pointer p, size_type n)
 

Detailed Description

template<typename T>
class grad::GradientAllocator< T >

Definition at line 148 of file gradient.h.

Member Typedef Documentation

template<typename T>
typedef std::allocator<T>::const_pointer grad::GradientAllocator< T >::const_pointer

Definition at line 154 of file gradient.h.

template<typename T>
typedef std::allocator<T>::const_reference grad::GradientAllocator< T >::const_reference

Definition at line 156 of file gradient.h.

template<typename T>
typedef std::allocator<T>::difference_type grad::GradientAllocator< T >::difference_type

Definition at line 153 of file gradient.h.

template<typename T>
typedef std::allocator<T>::pointer grad::GradientAllocator< T >::pointer

Definition at line 150 of file gradient.h.

template<typename T>
typedef std::allocator<T>::reference grad::GradientAllocator< T >::reference

Definition at line 155 of file gradient.h.

template<typename T>
typedef std::allocator<T>::size_type grad::GradientAllocator< T >::size_type

Definition at line 151 of file gradient.h.

template<typename T>
typedef std::allocator<T>::value_type grad::GradientAllocator< T >::value_type

Definition at line 157 of file gradient.h.

Constructor & Destructor Documentation

template<typename T>
grad::GradientAllocator< T >::GradientAllocator ( )
throw (
)
inline

Definition at line 164 of file gradient.h.

164 { }
template<typename T>
grad::GradientAllocator< T >::GradientAllocator ( const GradientAllocator< T > &  a)
throw (
)
inline

Definition at line 166 of file gradient.h.

167  :std::allocator<T>(a) {
168  }
static const doublereal a
Definition: hfluid_.h:289
template<typename T>
template<typename U >
grad::GradientAllocator< T >::GradientAllocator ( const GradientAllocator< U > &  a)
throw (
)
inline

Definition at line 171 of file gradient.h.

172  :std::allocator<T>(a) {
173  }
static const doublereal a
Definition: hfluid_.h:289

Member Function Documentation

template<typename T>
pointer grad::GradientAllocator< T >::allocate ( size_type  n,
const void *  p = 0 
)
inline

Definition at line 176 of file gradient.h.

176  {
177 #if GRADIENT_MEMORY_STAT > 0
178  sMemUsage.Inc(n);
179 #endif
180 
181  const pointer pMem = std::allocator<T>::allocate(n, p);
182 
183 #if GRADIENT_DEBUG > 0
184  std::memset(pMem, 0xFF, n);
185 #endif
186  return pMem;
187  }
std::allocator< T >::pointer pointer
Definition: gradient.h:150
template<typename T>
static T* grad::GradientAllocator< T >::allocate_aligned ( size_type  alignment,
size_t  n,
size_type  extra_bytes = 0u 
)
inlinestatic

Definition at line 198 of file gradient.h.

References GRADIENT_ASSERT.

Referenced by grad::RangeVector< T, 0 >::ReserveMem().

198  {
199 #if GRADIENT_MEMORY_STAT > 0
200  sMemUsage.Inc(n);
201 #endif
202  void* p;
203 
204  const size_type byte_size = sizeof(T) * n + extra_bytes;
205 
206  GRADIENT_ASSERT(alignment % sizeof(void*) == 0);
207 
208 #if defined(HAVE_POSIX_MEMALIGN)
209  if (0 != posix_memalign(&p, alignment, byte_size)) {
210  p = 0;
211  }
212 #elif defined(HAVE_MEMALIGN)
213  p = memalign(alignment, byte_size);
214 #elif defined(HAVE_ALIGNED_MALLOC)
215  p = _aligned_malloc(byte_size, alignment);
216 #else
217  p = malloc(byte_size);
218 #endif
219  if (p == 0) {
220  throw std::bad_alloc();
221  }
222 
223 #if GRADIENT_DEBUG > 0
224  const ptrdiff_t alignment_curr = (reinterpret_cast<const char*>(p) - reinterpret_cast<const char*>(0)) % sizeof(alignment);
225 
226  if (alignment_curr != 0) {
227  silent_cout("address " << p << " has invalid alignment " << alignment_curr << std::endl);
228  }
229 
230  GRADIENT_ASSERT(alignment_curr == 0);
231 
232  std::memset(p, 0xFF, byte_size);
233 #endif
234  return reinterpret_cast<T*>(p);
235  }
std::allocator< T >::size_type size_type
Definition: gradient.h:151
#define GRADIENT_ASSERT(expr)
Definition: gradient.h:74
template<typename T>
void grad::GradientAllocator< T >::deallocate ( pointer  p,
size_type  n 
)
inline

Definition at line 190 of file gradient.h.

190  {
191  std::allocator<T>::deallocate(p, n);
192 
193 #if GRADIENT_MEMORY_STAT > 0
194  sMemUsage.Dec(n);
195 #endif
196  }
template<typename T>
static void grad::GradientAllocator< T >::deallocate_aligned ( pointer  p,
size_type  n 
)
inlinestatic

Definition at line 239 of file gradient.h.

Referenced by grad::RangeVector< T, 0 >::FreeMem().

239  {
240 #if defined(HAVE_ALIGNED_MALLOC)
241  _aligned_free(p);
242 #else
243  free(p);
244 #endif
245 
246 #if GRADIENT_MEMORY_STAT > 0
247  sMemUsage.Dec(n);
248 #endif
249  }

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