MRPT  2.0.4
aligned_malloc.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "core-precomp.h" // Precompiled headers
11 
13 #include <cstdlib> // free, realloc, C++17 aligned_alloc
14 #include <cstring> // memset
15 
16 void* mrpt::aligned_calloc(size_t bytes, size_t alignment)
17 {
18  void* ptr = mrpt::aligned_malloc(bytes, alignment);
19  if (ptr) ::memset(ptr, 0, bytes);
20  return ptr;
21 }
22 void* mrpt::aligned_malloc(size_t size, size_t alignment)
23 {
24  // size must be an integral multiple of alignment:
25  if (alignment != 0 && (size % alignment) != 0)
26  size = ((size / alignment) + 1) * alignment;
27 #ifdef _MSC_VER
28  return _aligned_malloc(size, alignment);
29 #elif __APPLE__
30  void* p;
31  if (::posix_memalign(&p, alignment, size) != 0)
32  {
33  p = 0;
34  }
35  return p;
36 #else
37  return ::aligned_alloc(alignment, size);
38 #endif
39 }
40 void mrpt::aligned_free(void* ptr)
41 {
42 #ifdef _MSC_VER
43  return _aligned_free(ptr);
44 #else
45  return ::free(ptr);
46 #endif
47 }
48 void* mrpt::aligned_realloc(void* ptr, size_t size, size_t alignment)
49 {
50  // size must be an integral multiple of alignment:
51  if ((size % alignment) != 0) size = ((size / alignment) + 1) * alignment;
52 #ifdef _MSC_VER
53  return _aligned_realloc(ptr, size, alignment);
54 #else
55  return std::realloc(ptr, size);
56 #endif
57 }
void aligned_free(void *ptr)
size_t size(const MATRIXLIKE &m, const int dim)
void * aligned_malloc(size_t size, size_t alignment)
void * aligned_realloc(void *ptr, size_t size, size_t alignment)
void * aligned_calloc(size_t bytes, size_t alignment)
Identical to aligned_malloc, but it zeroes the reserved memory block.



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020