Main MRPT website > C++ reference for MRPT 1.9.9
Classes | Macros | Functions
Memory utilities (in #include

Detailed Description

<mrpt/system/memory.h>)

Collaboration diagram for Memory utilities (in #include:

Classes

class  mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >
 A generic system for versatile memory pooling. More...
 

Macros

#define mrpt_alloca(nBytes)   ::malloc(nBytes)
 In platforms and compilers with support to "alloca", allocate a memory block on the stack; if alloca is not supported, it is emulated as a normal "malloc". More...
 
#define mrpt_alloca_free(mem_block)   free(mem_block)
 This method must be called to "free" each memory block allocated with "system::alloca": If the block was really allocated in the stack, no operation is actually performed, otherwise it will be freed from the heap. More...
 

Functions

unsigned long mrpt::system::getMemoryUsage ()
 Returns the memory occupied by this process, in bytes. More...
 
voidmrpt::system::os::aligned_malloc (size_t bytes, size_t alignment)
 Returns an aligned memory block. More...
 
voidmrpt::system::os::aligned_calloc (size_t bytes, size_t alignment)
 Identical to aligned_malloc, but it zeroes the reserved memory block. More...
 
voidmrpt::system::os::aligned_realloc (void *old_ptr, size_t bytes, size_t alignment)
 Frees a memory block reserved by aligned_malloc. More...
 
void mrpt::system::os::aligned_free (void *p)
 Frees a memory block reserved by aligned_malloc. More...
 
template<typename _Tp >
_Tp * mrpt::system::os::align_ptr (_Tp *ptr, int n=(int) sizeof(_Tp))
 Returns a pointer a bit forward in memory so it's aligned for the given boundary size. More...
 
template<int bytes>
bool mrpt::system::is_aligned (const void *ptr)
 
template<>
bool mrpt::system::is_aligned< 8 > (const void *ptr)
 
template<>
bool mrpt::system::is_aligned< 16 > (const void *ptr)
 

Macro Definition Documentation

◆ mrpt_alloca

#define mrpt_alloca (   nBytes)    ::malloc(nBytes)

In platforms and compilers with support to "alloca", allocate a memory block on the stack; if alloca is not supported, it is emulated as a normal "malloc".

  • NOTICE: Since in some platforms alloca will be emulated with malloc, alloca_free MUST BE ALWAYS CALLED to avoid memory leaks. This method MUST BE a macro rather than a function in order to operate on the caller's stack.
    See also
    mrpt_alloca_free

Definition at line 43 of file memory.h.

Referenced by mrpt::maps::COccupancyGridMap2D::internal_insertObservation(), and mrpt::vision::CFeatureTracker_KL::trackFeatures_impl_templ().

◆ mrpt_alloca_free

#define mrpt_alloca_free (   mem_block)    free(mem_block)

This method must be called to "free" each memory block allocated with "system::alloca": If the block was really allocated in the stack, no operation is actually performed, otherwise it will be freed from the heap.

This method MUST BE a macro rather than a function in order to operate on the caller's stack.

See also
mrpt_alloca

Definition at line 61 of file memory.h.

Referenced by mrpt::maps::COccupancyGridMap2D::internal_insertObservation(), and mrpt::vision::CFeatureTracker_KL::trackFeatures_impl_templ().

Function Documentation

◆ align_ptr()

template<typename _Tp >
_Tp* mrpt::system::os::align_ptr ( _Tp *  ptr,
int  n = (int)sizeof(_Tp) 
)
inline

Returns a pointer a bit forward in memory so it's aligned for the given boundary size.

Note
Function copied from OpenCV with a different name to avoid conflicts.

Definition at line 105 of file memory.h.

◆ aligned_calloc()

void* mrpt::system::os::aligned_calloc ( size_t  bytes,
size_t  alignment 
)
inline

Identical to aligned_malloc, but it zeroes the reserved memory block.

Definition at line 80 of file memory.h.

References mrpt::system::os::aligned_malloc().

Referenced by mrpt::math::CMatrixTemplate< mrpt::math::TPoint3D >::realloc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ aligned_free()

void mrpt::system::os::aligned_free ( void p)

Frees a memory block reserved by aligned_malloc.

See also
aligned_malloc

Definition at line 87 of file memory.cpp.

Referenced by mrpt::aligned_allocator_cpp11< T, AligmentBytes >::deallocate(), and mrpt::math::CMatrixTemplate< mrpt::math::TPoint3D >::realloc().

Here is the caller graph for this function:

◆ aligned_malloc()

void * mrpt::system::os::aligned_malloc ( size_t  bytes,
size_t  alignment 
)

Returns an aligned memory block.

Parameters
alignmentThe desired alignment, typ. 8 or 16 bytes. 1 means no alignment required. It must be a power of two.
See also
aligned_free, aligned_realloc, aligned_calloc
Note
Based on code by William Chan
Parameters
alignmentThe desired alignment, typ. 8 or 16 bytes. 1 means no alignment required. It must be a power of two.
See also
aligned_free, aligned_realloc
Note
Based on code by William Chan

Definition at line 40 of file memory.cpp.

References THROW_EXCEPTION.

Referenced by mrpt::system::os::aligned_calloc(), and mrpt::aligned_allocator_cpp11< T, AligmentBytes >::allocate().

Here is the caller graph for this function:

◆ aligned_realloc()

void * mrpt::system::os::aligned_realloc ( void old_ptr,
size_t  bytes,
size_t  alignment 
)

Frees a memory block reserved by aligned_malloc.

Parameters
alignmentThe desired alignment, typ. 8 or 16 bytes. 1 means no alignment required. If old_ptr is nullptr, a new block will be reserved from scratch.
See also
aligned_malloc, aligned_free

Definition at line 65 of file memory.cpp.

References MRPT_UNUSED_PARAM.

Referenced by mrpt::math::CMatrixTemplate< mrpt::math::TPoint3D >::realloc().

Here is the caller graph for this function:

◆ getMemoryUsage()

unsigned long mrpt::system::getMemoryUsage ( )

Returns the memory occupied by this process, in bytes.

Definition at line 185 of file memory.cpp.

References mrpt::system::os::fclose(), mrpt::system::os::fopen(), MEM, MRPT_END, and MRPT_START.

Referenced by mrpt::hmtslam::CHMTSLAM::generateLogFiles().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_aligned()

template<int bytes>
bool mrpt::system::is_aligned ( const void ptr)

◆ is_aligned< 16 >()

template<>
bool mrpt::system::is_aligned< 16 > ( const void ptr)
inline

◆ is_aligned< 8 >()

template<>
bool mrpt::system::is_aligned< 8 > ( const void ptr)
inline

Definition at line 121 of file memory.h.




Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019