30 #if defined(_MSC_VER) && (_MSC_VER>=1400) 32 # define mrpt_alloca( nBytes ) _malloca(nBytes) 33 #elif defined(HAVE_ALLOCA) 35 # define mrpt_alloca( nBytes ) ::alloca(nBytes) 38 # define mrpt_alloca( nBytes ) ::malloc( nBytes ) 45 #if defined(_MSC_VER) && (_MSC_VER>=1400) 47 # define mrpt_alloca_free( mem_block ) _freea(mem_block) 48 #elif defined(HAVE_ALLOCA) 50 # define mrpt_alloca_free( mem_block ) 53 # define mrpt_alloca_free( mem_block ) free(mem_block) 74 if (ptr) ::memset(ptr,0,bytes);
93 template<
typename _Tp>
inline _Tp*
align_ptr(_Tp* ptr,
int n=(
int)
sizeof(_Tp))
95 return (_Tp*)(((size_t)ptr +
n-1) & -
n);
105 template<
int bytes>
bool is_aligned(
const void* ptr);
106 template<>
inline bool is_aligned<8>(
const void* ptr) {
return ((reinterpret_cast<size_t>(ptr)) & 0x7) == 0; }
107 template<>
inline bool is_aligned<16>(
const void* ptr) {
return ((reinterpret_cast<size_t>(ptr)) & 0xF) == 0; }
112 #define MRPT_MAKE_ALIGNED_OPERATOR_NEW \ 113 void *operator new(size_t size) { return mrpt::system::os::aligned_malloc(size,16); } \ 114 void *operator new[](size_t size){ return mrpt::system::os::aligned_malloc(size,16); } \ 115 void operator delete(void * ptr) MRPT_NO_THROWS { mrpt::system::os::aligned_free(ptr); } \ 116 void operator delete[](void * ptr) MRPT_NO_THROWS { mrpt::system::os::aligned_free(ptr); } \ 120 static void *operator new(size_t size, void *ptr) { return ::operator new(size,ptr); } \ 121 void operator delete(void * memory, void *ptr) MRPT_NO_THROWS { return ::operator delete(memory,ptr); } \ 123 void* operator new(size_t size, const std::nothrow_t&) MRPT_NO_THROWS { try { return mrpt::system::os::aligned_malloc(size,16); } catch (...) { return 0; } } \ 124 void operator delete(void *ptr, const std::nothrow_t&) MRPT_NO_THROWS { mrpt::system::os::aligned_free(ptr); } bool is_aligned< 8 >(const void *ptr)
bool is_aligned< 16 >(const void *ptr)
void BASE_IMPEXP * aligned_realloc(void *old_ptr, size_t bytes, size_t alignment)
Frees a memory block reserved by aligned_malloc.
_Tp * 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.
void * aligned_calloc(size_t bytes, size_t alignment)
Identical to aligned_malloc, but it zeroes the reserved memory block.
bool is_aligned(const void *ptr)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
unsigned long BASE_IMPEXP getMemoryUsage()
Returns the memory occupied by this process, in bytes.
void BASE_IMPEXP * aligned_malloc(size_t bytes, size_t alignment)
Returns an aligned memory block.
void BASE_IMPEXP aligned_free(void *p)
Frees a memory block reserved by aligned_malloc.