MCPcopy Create free account
hub / github.com/RenderKit/oidn / alignedMalloc

Function alignedMalloc

common/platform.cpp:6–30  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4#include "platform.h"
5
6OIDN_NAMESPACE_BEGIN
7
8 // -----------------------------------------------------------------------------------------------
9 // Common functions
10 // -----------------------------------------------------------------------------------------------
11
12 void* alignedMalloc(size_t size, size_t alignment)
13 {
14 if (size == 0)
15 return nullptr;
16
17 assert((alignment & (alignment-1)) == 0);
18 #if defined(OIDN_ARCH_X64) || defined(_MSC_VER)
19 void* ptr = _mm_malloc(size, alignment);
20 #else
21 void* ptr;
22 if (posix_memalign(&ptr, max(alignment, sizeof(void*)), size) != 0)
23 ptr = nullptr;
24 #endif
25
26 if (ptr == nullptr)
27 throw std::bad_alloc();
28
29 return ptr;
30 }
31
32 void alignedFree(void* ptr)
33 {

Callers 2

usmAllocMethod · 0.85
HostTensorMethod · 0.85

Calls 1

maxFunction · 0.70

Tested by

no test coverage detected