Main MRPT website > C++ reference for MRPT 1.9.9
aligned_malloc.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "core-precomp.h" // Precompiled headers
12 #include <cstdlib> // free, realloc, C++17 aligned_alloc
13 #include <cstring> // memset
14 
15 void* mrpt::aligned_calloc(size_t bytes, size_t alignment)
16 {
17  void* ptr = mrpt::aligned_malloc(bytes, alignment);
18  if (ptr) ::memset(ptr, 0, bytes);
19  return ptr;
20 }
21 void* mrpt::aligned_malloc(size_t size, size_t alignment)
22 {
23  // size must be an integral multiple of alignment:
24  if ((size % alignment) != 0) size = ((size / alignment) + 1) * alignment;
25 #ifdef _MSC_VER
26  return _aligned_malloc(size, alignment);
27 #else
28  return ::aligned_alloc(alignment, size);
29 #endif
30 }
31 void mrpt::aligned_free(void* ptr)
32 {
33 #ifdef _MSC_VER
34  return _aligned_free(ptr);
35 #else
36  return ::free(ptr);
37 #endif
38 }
39 void* mrpt::aligned_realloc(void* ptr, size_t size, size_t alignment)
40 {
41  // size must be an integral multiple of alignment:
42  if ((size % alignment) != 0) size = ((size / alignment) + 1) * alignment;
43 #ifdef _MSC_VER
44  return _aligned_realloc(ptr, size, alignment);
45 #else
46  return std::realloc(ptr, size);
47 #endif
48 }
mrpt::aligned_free
void aligned_free(void *ptr)
Definition: aligned_malloc.cpp:31
aligned_allocator.h
core-precomp.h
mrpt::aligned_malloc
void * aligned_malloc(size_t size, size_t alignment)
Definition: aligned_malloc.cpp:21
mrpt::aligned_realloc
void * aligned_realloc(void *ptr, size_t size, size_t alignment)
Definition: aligned_malloc.cpp:39
mrpt::aligned_calloc
void * aligned_calloc(size_t bytes, size_t alignment)
Identical to aligned_malloc, but it zeroes the reserved memory block.
Definition: aligned_malloc.cpp:15
size
GLsizeiptr size
Definition: glext.h:3923



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST