| 31 | #endif |
| 32 | |
| 33 | CCL_NAMESPACE_BEGIN |
| 34 | |
| 35 | void *util_aligned_malloc(const size_t size, const int alignment) |
| 36 | { |
| 37 | void *mem = nullptr; |
| 38 | #ifdef WITH_BLENDER_GUARDEDALLOC |
| 39 | mem = MEM_new_uninitialized_aligned(size, alignment, "Cycles Aligned Alloc"); |
| 40 | #elif defined(_WIN32) |
| 41 | mem = _aligned_malloc(size, alignment); |
| 42 | #elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) |
| 43 | if (posix_memalign(&mem, alignment, size)) { |
| 44 | /* Non-zero means allocation error |
| 45 | * either no allocation or bad alignment value. */ |
| 46 | mem = nullptr; |
| 47 | } |
| 48 | #else /* This is for Linux. */ |
| 49 | mem = memalign(alignment, size); |
| 50 | #endif |
| 51 | if (mem) { |
| 52 | util_guarded_mem_alloc(size); |
| 53 | } |
| 54 | return mem; |
| 55 | } |
| 56 | |
| 57 | void util_aligned_free(void *ptr, const size_t size) |
| 58 | { |