| 239 | } |
| 240 | |
| 241 | void* AlignedMalloc(size_t size, int minimum_alignment) { |
| 242 | #if defined(__ANDROID__) |
| 243 | return memalign(minimum_alignment, size); |
| 244 | #else // !defined(__ANDROID__) |
| 245 | void* ptr = nullptr; |
| 246 | // posix_memalign requires that the requested alignment be at least |
| 247 | // sizeof(void*). In this case, fall back on malloc which should return |
| 248 | // memory aligned to at least the size of a pointer. |
| 249 | const int required_alignment = sizeof(void*); |
| 250 | if (minimum_alignment < required_alignment) return Malloc(size); |
| 251 | int err = posix_memalign(&ptr, minimum_alignment, size); |
| 252 | if (err != 0) { |
| 253 | return nullptr; |
| 254 | } else { |
| 255 | return ptr; |
| 256 | } |
| 257 | #endif |
| 258 | } |
| 259 | |
| 260 | void AlignedFree(void* aligned_memory) { Free(aligned_memory); } |
| 261 | |