1 |
|
|
/*************************************** |
2 |
|
|
Auteur : Pierre Aubert |
3 |
|
|
Mail : pierre.aubert@lapp.in2p3.fr |
4 |
|
|
Licence : CeCILL-C |
5 |
|
|
****************************************/ |
6 |
|
|
|
7 |
|
|
#include <stdlib.h> |
8 |
|
|
#include <stdint.h> //pour uintptr_t |
9 |
|
|
#include <stdio.h> |
10 |
|
|
|
11 |
|
|
#include "pallocAlignedVector.h" |
12 |
|
|
|
13 |
|
|
#ifndef __APPLE__ |
14 |
|
|
# include <malloc.h> |
15 |
|
|
#endif |
16 |
|
|
|
17 |
|
|
#ifdef __APPLE__ |
18 |
|
|
///Alloc an aligned vector |
19 |
|
|
/** @param sizeOfVectorInBytes : size of the vector xe want to allocate |
20 |
|
|
* @param alignementInBytes : alignement of the vector we want to allocate |
21 |
|
|
* @return aligned pointor of the vector |
22 |
|
|
*/ |
23 |
|
|
void * memalign(size_t alignementInBytes,size_t sizeOfVectorInBytes){ |
24 |
|
|
void * ptr = NULL; |
25 |
|
|
posix_memalign(&ptr, alignementInBytes, sizeOfVectorInBytes); |
26 |
|
|
return ptr; |
27 |
|
|
} |
28 |
|
|
#endif |
29 |
|
|
|
30 |
|
|
///Alloc an aligned vector |
31 |
|
|
/** @param sizeOfVectorInBytes : size of the vector xe want to allocate |
32 |
|
|
* @param alignementInBytes : alignement of the vector we want to allocate |
33 |
|
|
* @return aligned pointor of the vector |
34 |
|
|
*/ |
35 |
|
1119 |
void* pallocAlignedTab(size_t sizeOfVectorInBytes, size_t alignementInBytes){ |
36 |
|
|
// return aligned_alloc(alignementInBytes, sizeOfVectorInBytes); |
37 |
|
1119 |
return memalign(alignementInBytes, sizeOfVectorInBytes); |
38 |
|
|
} |
39 |
|
|
|
40 |
|
|
///Free the aligned vector |
41 |
|
|
/** @param ptr : pointor we want to free |
42 |
|
|
* |
43 |
|
|
* Usage : |
44 |
|
|
* void* mem = pallocAlignedVector(alignedVector, sizeOfVectorInBytes, alignementInBytes); |
45 |
|
|
* ... |
46 |
|
|
* Using of alignedVector pointor |
47 |
|
|
* ... |
48 |
|
|
* freeAlignedVector(mem); |
49 |
|
|
*/ |
50 |
|
1119 |
void freeAlignedVector(void* ptr){ |
51 |
✗✓ |
1119 |
if(ptr == NULL) return; |
52 |
|
1119 |
free(ptr); |
53 |
|
|
} |
54 |
|
|
|
55 |
|
|
|