MCPcopy Create free account
hub / github.com/ErrorAtLine0/infinipaint / handmade_aligned_malloc

Function handmade_aligned_malloc

include/Eigen/src/Core/util/Memory.h:142–155  ·  view source on GitHub ↗

\internal Like malloc, but the returned pointer is guaranteed to be aligned to `alignment`. * Fast, but wastes `alignment` additional bytes of memory. Does not throw any exception. */

Source from the content-addressed store, hash-verified

140 * Fast, but wastes `alignment` additional bytes of memory. Does not throw any exception.
141 */
142EIGEN_DEVICE_FUNC inline void* handmade_aligned_malloc(std::size_t size,
143 std::size_t alignment = EIGEN_DEFAULT_ALIGN_BYTES) {
144 eigen_assert(alignment >= sizeof(void*) && alignment <= 128 && (alignment & (alignment - 1)) == 0 &&
145 "Alignment must be at least sizeof(void*), less than or equal to 128, and a power of 2");
146
147 check_that_malloc_is_allowed();
148 EIGEN_USING_STD(malloc)
149 void* original = malloc(size + alignment);
150 if (original == nullptr) return nullptr;
151 uint8_t offset = static_cast<uint8_t>(alignment - (reinterpret_cast<std::size_t>(original) & (alignment - 1)));
152 void* aligned = static_cast<void*>(static_cast<uint8_t*>(original) + offset);
153 *(static_cast<uint8_t*>(aligned) - 1) = offset;
154 return aligned;
155}
156
157/** \internal Frees memory allocated with handmade_aligned_malloc */
158EIGEN_DEVICE_FUNC inline void handmade_aligned_free(void* ptr) {

Callers 5

triSolveFunction · 0.85
MaxSizeVectorFunction · 0.85
MaxSizeVector.hFile · 0.85
handmade_aligned_reallocFunction · 0.85
aligned_mallocFunction · 0.85

Calls 1

Tested by

no test coverage detected