\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. */
| 104 | * we can use std::realloc to implement efficient reallocation. |
| 105 | */ |
| 106 | inline 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 *** |
no test coverage detected