MCPcopy Create free account
hub / github.com/PX4/eigen / handmade_aligned_realloc

Function handmade_aligned_realloc

Eigen/src/Core/util/Memory.h:106–120  ·  view source on GitHub ↗

\internal * \brief Reallocates aligned memory. * Since we know that our handmade version is based on std::malloc * we can use std::realloc to implement efficient reallocation. */

Source from the content-addressed store, hash-verified

104 * we can use std::realloc to implement efficient reallocation.
105 */
106inline void* handmade_aligned_realloc(void* ptr, std::size_t size, std::size_t = 0)
107{
108 if (ptr == 0) return handmade_aligned_malloc(size);
109 void *original = *(reinterpret_cast<void**>(ptr) - 1);
110 std::ptrdiff_t previous_offset = static_cast<char *>(ptr)-static_cast<char *>(original);
111 original = std::realloc(original,size+EIGEN_DEFAULT_ALIGN_BYTES);
112 if (original == 0) return 0;
113 void *aligned = reinterpret_cast<void*>((reinterpret_cast<std::size_t>(original) & ~(std::size_t(EIGEN_DEFAULT_ALIGN_BYTES-1))) + EIGEN_DEFAULT_ALIGN_BYTES);
114 void *previous_aligned = static_cast<char *>(original)+previous_offset;
115 if(aligned!=previous_aligned)
116 std::memmove(aligned, previous_aligned, size);
117
118 *(reinterpret_cast<void**>(aligned) - 1) = original;
119 return aligned;
120}
121
122/*****************************************************************************
123*** Implementation of portable aligned versions of malloc/free/realloc ***

Callers 1

aligned_reallocFunction · 0.85

Calls 1

handmade_aligned_mallocFunction · 0.85

Tested by

no test coverage detected