PhoenixHardware
0.2.0
Tools to get hardware information
Toggle main menu visibility
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
17
#include "
phoenix_template_alloc.h
"
18
20
template
<
class
T>
21
struct
PAlignedAllocator
{
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
}
40
T* p =
phoenix_template_alloc_aligned1d<T>
(n);
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
{
51
phoenix_freeAlignedVector
(p);
52
}
53
};
54
55
56
57
#endif
58
phoenix_freeAlignedVector
void phoenix_freeAlignedVector(void *ptr)
Free the aligned vector.
Definition
phoenix_allocAlignedVector.cpp:49
phoenix_template_alloc.h
phoenix_template_alloc_aligned1d
T * phoenix_template_alloc_aligned1d(size_t nbValue)
Do a template allcoation of a type.
Definition
phoenix_template_alloc_impl.h:72
PAlignedAllocator::value_type
T value_type
Value of the type of the current allocator (used by std::vector to avoid ambiguities if we use multip...
Definition
PAlignedAllocator.h:23
PAlignedAllocator::deallocate
static void deallocate(T *p, std::size_t n) noexcept
Free the allocated memory.
Definition
PAlignedAllocator.h:50
PAlignedAllocator::allocate
static T * allocate(std::size_t n)
Do the memory allocation.
Definition
PAlignedAllocator.h:36
PAlignedAllocator::PAlignedAllocator
PAlignedAllocator()=default
PAlignedAllocator::PAlignedAllocator
constexpr PAlignedAllocator(const PAlignedAllocator< U > &) noexcept
Copy constructor from U type.
Definition
PAlignedAllocator.h:28
src
PAlignedAllocator.h
Generated by
1.17.0