Blender  V2.93
aligned_malloc.cc
Go to the documentation of this file.
1 // Copyright (c) 2014 libmv authors.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to
5 // deal in the Software without restriction, including without limitation the
6 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 // sell copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 // IN THE SOFTWARE.
20 
22 #include "libmv/logging/logging.h"
23 
24 #if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__NetBSD__)
25 // Needed for memalign on Linux and _aligned_alloc on Windows.
26 # ifdef FREE_WINDOWS
27 /* make sure _aligned_malloc is included */
28 # ifdef __MSVCRT_VERSION__
29 # undef __MSVCRT_VERSION__
30 # endif
31 
32 # define __MSVCRT_VERSION__ 0x0700
33 # endif // FREE_WINDOWS
34 
35 # include <malloc.h>
36 #else
37 // Apple's malloc is 16-byte aligned, and does not have malloc.h, so include
38 // stdilb instead.
39 # include <cstdlib>
40 #endif
41 
42 namespace libmv {
43 
44 void* aligned_malloc(int size, int alignment) {
45 #ifdef _WIN32
46  return _aligned_malloc(size, alignment);
47 #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__)
48  void* result;
49 
50  if (posix_memalign(&result, alignment, size)) {
51  // non-zero means allocation error
52  // either no allocation or bad alignment value
53  return NULL;
54  }
55  return result;
56 #else // This is for Linux.
57  return memalign(alignment, size);
58 #endif
59 }
60 
61 void aligned_free(void* ptr) {
62 #ifdef _WIN32
63  _aligned_free(ptr);
64 #else
65  free(ptr);
66 #endif
67 }
68 
69 } // namespace libmv
void BLI_kdtree_nd_() free(KDTree *tree)
Definition: kdtree_impl.h:116
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
void aligned_free(void *ptr)
void * aligned_malloc(int size, int alignment)
PointerRNA * ptr
Definition: wm_files.c:3157