Main MRPT website
>
C++ reference for MRPT 1.9.9
mrpt
system
memory.h
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
#pragma once
10
11
#include <cstring>
12
#include <type_traits>
13
14
namespace
mrpt
15
{
16
namespace
system
17
{
18
/** \addtogroup mrpt_memory Memory utilities (#include <mrpt/system/memory.h>)
19
* \ingroup mrpt_system_grp
20
* @{ */
21
22
/** Returns the memory occupied by this process, in bytes */
23
unsigned
long
getMemoryUsage
();
24
25
/** In platforms and compilers with support to "alloca", allocate a memory block
26
* on the stack; if alloca is not supported, it is emulated as a normal "malloc"
27
* - NOTICE: Since in some platforms alloca will be emulated with malloc,
28
* alloca_free MUST BE ALWAYS CALLED to avoid memory leaks.
29
* This method MUST BE a macro rather than a function in order to operate on
30
* the caller's stack.
31
* \sa mrpt_alloca_free
32
*/
33
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
34
// Visual Studio 2005, 2008
35
#define mrpt_alloca(nBytes) _malloca(nBytes)
36
#elif defined(HAVE_ALLOCA)
37
// GCC
38
#define mrpt_alloca(nBytes) ::alloca(nBytes)
39
#else
40
// Default: Emulate with memory in the heap:
41
#define mrpt_alloca(nBytes) ::malloc(nBytes)
42
#endif
43
44
/** This method must be called to "free" each memory block allocated with
45
* "system::alloca": If the block was really allocated in the stack, no
46
* operation is actually performed, otherwise it will be freed from the heap.
47
* This method MUST BE a macro rather than a function in order to operate on
48
* the caller's stack.
49
* \sa mrpt_alloca
50
*/
51
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
52
// Visual Studio 2005, 2008
53
#define mrpt_alloca_free(mem_block) _freea(mem_block)
54
#elif defined(HAVE_ALLOCA)
55
// GCC
56
#define mrpt_alloca_free(mem_block)
57
#else
58
// Default: Emulate with memory in the heap:
59
#define mrpt_alloca_free(mem_block) free(mem_block)
60
#endif
61
62
/** @} */
63
64
/** \addtogroup mrpt_memory Memory utilities
65
* @{ */
66
template <std::size_t alignment, typename T, typename = std::enable_if_t<std::is_pointer<T>::value
>>
67
bool
is_aligned
(T ptr)
68
{
69
return
reinterpret_cast<
std::size_t
>
(ptr) % alignment == 0;
70
}
71
/** @} */
72
73
}
// namespace system
74
}
// namespace mrpt
mrpt::system::getMemoryUsage
unsigned long getMemoryUsage()
Returns the memory occupied by this process, in bytes.
Definition:
memory.cpp:110
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition:
CKalmanFilterCapable.h:30
value
GLsizei const GLfloat * value
Definition:
glext.h:4117
mrpt::system::is_aligned
bool is_aligned(T ptr)
Definition:
memory.h:67
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