Inline memory allocation routines here, because depending on '//base' brings in libraries which use c++ streams, which adds considerable code size on android.
| 23 | // in libraries which use c++ streams, which adds considerable code size on |
| 24 | // android. |
| 25 | void* aligned_malloc(size_t size, int minimum_alignment) { |
| 26 | #if defined(__ANDROID__) || defined(OS_ANDROID) || defined(OS_CYGWIN) |
| 27 | return memalign(minimum_alignment, size); |
| 28 | #elif defined(_WIN32) |
| 29 | return _aligned_malloc(size, minimum_alignment); |
| 30 | #else // !__ANDROID__ && !OS_ANDROID && !OS_CYGWIN |
| 31 | void* ptr = nullptr; |
| 32 | // posix_memalign requires that the requested alignment be at least |
| 33 | // sizeof(void*). In this case, fall back on malloc which should return memory |
| 34 | // aligned to at least the size of a pointer. |
| 35 | const int required_alignment = sizeof(void*); |
| 36 | if (minimum_alignment < required_alignment) return malloc(size); |
| 37 | if (posix_memalign(&ptr, minimum_alignment, size) != 0) |
| 38 | return nullptr; |
| 39 | else |
| 40 | return ptr; |
| 41 | #endif |
| 42 | } |
| 43 | |
| 44 | void aligned_free(void* aligned_memory) { |
| 45 | #if defined(_WIN32) |
no outgoing calls