Blender V4.3
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
23
24#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && \
25 !defined(__OpenBSD__)
26// Needed for memalign on Linux and _aligned_alloc on Windows.
27# ifdef FREE_WINDOWS
28/* make sure _aligned_malloc is included */
29# ifdef __MSVCRT_VERSION__
30# undef __MSVCRT_VERSION__
31# endif
32
33# define __MSVCRT_VERSION__ 0x0700
34# endif // FREE_WINDOWS
35
36# include <malloc.h>
37#else
38// Apple's malloc is 16-byte aligned, and does not have malloc.h, so include
39// stdilb instead.
40# include <cstdlib>
41#endif
42
43namespace libmv {
44
45void* aligned_malloc(int size, int alignment) {
46#ifdef _WIN32
47 return _aligned_malloc(size, alignment);
48#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || \
49 defined(__OpenBSD__)
50 void* result;
51
52 if (posix_memalign(&result, alignment, size)) {
53 // non-zero means allocation error
54 // either no allocation or bad alignment value
55 return NULL;
56 }
57 return result;
58#else // This is for Linux.
59 return memalign(alignment, size);
60#endif
61}
62
63void aligned_free(void* ptr) {
64#ifdef _WIN32
65 _aligned_free(ptr);
66#else
67 free(ptr);
68#endif
69}
70
71} // namespace libmv
void BLI_kdtree_nd_ free(KDTree *tree)
#define NULL
void aligned_free(void *ptr)
void * aligned_malloc(int size, int alignment)
PointerRNA * ptr
Definition wm_files.cc:4126