LIBINT  2.1.0-stable
include/libint2/memory.h
1 /*
2  * This file is a part of Libint.
3  * Copyright (C) 2004-2014 Edward F. Valeev
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Library General Public License, version 2,
7  * as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this program. If not, see http://www.gnu.org/licenses/.
16  *
17  */
18 
19 #ifndef _libint2_src_lib_libint_libint2memory_h_
20 #define _libint2_src_lib_libint_libint2memory_h_
21 
22 #include <cstdlib>
23 #include <libint2_params.h>
24 
25 namespace libint2 {
26 
28 
31  inline void* malloc(size_t nbytes) {
32  void* result;
33 #if (LIBINT2_ALIGN_SIZE == 0)
34  result = ::malloc(nbytes);
35 #elif defined(HAVE_POSIX_MEMALIGN)
36  posix_memalign(&result, LIBINT2_ALIGN_SIZE*sizeof(LIBINT2_REALTYPE), nbytes);
37 #else
38 # error "LIBINT2_ALIGN_SIZE!=0 but posix_memalign is not available"
39 #endif
40  return result;
41  }
42 
44  template <typename T>
45  inline T* malloc(size_t n) {
46  return reinterpret_cast<T*>(malloc(n * sizeof(T)));
47  }
48 
49 }
50 
51 #endif /* _libint2_src_lib_libint_libint2memory_h_ */
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:23
void * malloc(size_t nbytes)
Aligned version of malloc().
Definition: include/libint2/memory.h:31