MCPcopy Create free account
hub / github.com/catboost/catboost / std_cache_aligned_allocate

Function std_cache_aligned_allocate

contrib/libs/tbb/src/tbb/allocator.cpp:213–240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

211}
212
213static void* std_cache_aligned_allocate(std::size_t bytes, std::size_t alignment) {
214#if defined(__TBB_USE_MEMALIGN)
215 return memalign(alignment, bytes);
216#elif defined(__TBB_USE_POSIX_MEMALIGN)
217 void* p = nullptr;
218 int res = posix_memalign(&p, alignment, bytes);
219 if (res != 0)
220 p = nullptr;
221 return p;
222#elif defined(__TBB_USE_MSVC_ALIGNED_MALLOC)
223 return _aligned_malloc(bytes, alignment);
224#else
225 // TODO: make it common with cache_aligned_resource
226 std::size_t space = alignment + bytes;
227 std::uintptr_t base = reinterpret_cast<std::uintptr_t>(std::malloc(space));
228 if (!base) {
229 return nullptr;
230 }
231 std::uintptr_t result = (base + nfs_size) & ~(nfs_size - 1);
232 // Round up to the next cache line (align the base address)
233 __TBB_ASSERT((result - base) >= sizeof(std::uintptr_t), "Cannot store a base pointer to the header");
234 __TBB_ASSERT(space - (result - base) >= bytes, "Not enough space for the storage");
235
236 // Record where block actually starts.
237 (reinterpret_cast<std::uintptr_t*>(result))[-1] = base;
238 return reinterpret_cast<void*>(result);
239#endif
240}
241
242static void std_cache_aligned_deallocate(void* p) {
243#if defined(__TBB_USE_MEMALIGN) || defined(__TBB_USE_POSIX_MEMALIGN)

Callers

nothing calls this directly

Calls 4

_aligned_mallocFunction · 0.85
memalignFunction · 0.50
posix_memalignFunction · 0.50
mallocFunction · 0.50

Tested by

no test coverage detected