MCPcopy Create free account
hub / github.com/ARM-software/astc-encoder / aligned_malloc

Function aligned_malloc

Source/astcenc_internal.h:2192–2213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2190 */
2191template<typename T>
2192T* aligned_malloc(size_t size, size_t align)
2193{
2194 void* ptr;
2195 int error = 0;
2196
2197 // Don't allow this to under-align a type
2198 size_t min_align = astc::max(alignof(T), sizeof(void*));
2199 size_t real_align = astc::max(min_align, align);
2200
2201#if defined(_WIN32)
2202 ptr = _aligned_malloc(size, real_align);
2203#else
2204 error = posix_memalign(&ptr, real_align, size);
2205#endif
2206
2207 if (error || (!ptr))
2208 {
2209 return nullptr;
2210 }
2211
2212 return static_cast<T*>(ptr);
2213}
2214
2215/**
2216 * @brief Free an aligned memory buffer.

Callers

nothing calls this directly

Calls 1

maxFunction · 0.70

Tested by

no test coverage detected