PhoenixHardware  0.2.0
Tools to get hardware information
Loading...
Searching...
No Matches
PAlignedAllocator.h
Go to the documentation of this file.
1/***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5****************************************/
6
7#ifndef __PALIGNED_ALLOCATOR_H__
8#define __PALIGNED_ALLOCATOR_H__
9
10#include <new>
11#include <limits>
12#include <iostream>
13#include <vector>
14
15#include <malloc.h>
16
18
20template<class T>
23 typedef T value_type;
24 PAlignedAllocator () = default; //Declare the current constructor as default constructor
25
27 template<class U>
28 constexpr PAlignedAllocator (const PAlignedAllocator <U>&) noexcept {}
29
31
36 static /*[[nodiscard]]*/ T* allocate(std::size_t n){
37 if(n > std::numeric_limits<std::size_t>::max() / sizeof(T)){
38 throw std::bad_array_new_length();
39 }
41 if(p != NULL){
42 return p;
43 }
44 throw std::bad_alloc();
45 }
46
47
50 static void deallocate(T* p, std::size_t n) noexcept{
52 }
53};
54
55
56
57#endif
58
void phoenix_freeAlignedVector(void *ptr)
Free the aligned vector.
T * phoenix_template_alloc_aligned1d(size_t nbValue)
Do a template allcoation of a type.
T value_type
Value of the type of the current allocator (used by std::vector to avoid ambiguities if we use multip...
static void deallocate(T *p, std::size_t n) noexcept
Free the allocated memory.
static T * allocate(std::size_t n)
Do the memory allocation.
PAlignedAllocator()=default
constexpr PAlignedAllocator(const PAlignedAllocator< U > &) noexcept
Copy constructor from U type.