[go: up one dir, main page]

Menu

[8f591a]: / common / aligned_alloc.h  Maximize  Restore  History

Download this file

36 lines (27 with data), 825 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#ifndef ALIGNED_ALLOC
#define ALIGNED_ALLOC
/***************************************************************************
* aligned_alloc.h
*
* Sat Aug 24 23:53:12 2002
* Copyright 2002 Roman Dementiev
* dementiev@mpi-sb.mpg.de
****************************************************************************/
#include "../common/utils.h"
__STXXL_BEGIN_NAMESPACE
template < size_t ALIGNMENT >
inline void * aligned_alloc (size_t size)
{
// TODO: use posix_memalign() and free() on Linux
char *buffer = new char[size + ALIGNMENT];
char *result = buffer + ALIGNMENT - (unsigned (buffer) % ALIGNMENT);
*(((char **) result) - 1) = buffer;
return result;
};
template < size_t ALIGNMENT > inline void
aligned_dealloc (void *ptr)
{
delete[] * (((char **) ptr) - 1);
};
__STXXL_END_NAMESPACE
#endif