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

Function posix_memalign

library/cpp/balloc/balloc.cpp:120–145  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

118}
119
120int posix_memalign(void** memptr, const size_t alignment, const size_t size) {
121#if defined(Y_COVER_PTR)
122 (void)alignment;
123 *memptr = malloc(size);
124 return 0;
125#else
126 if (((alignment - 1) & alignment) != 0 || alignment < sizeof(void*)) {
127 return EINVAL;
128 }
129 if (alignment <= NBalloc::MINIMAL_ALIGNMENT) {
130 *memptr = NBalloc::Malloc(size);
131 return 0;
132 }
133 size_t bigSize = size + alignment - NBalloc::MINIMAL_ALIGNMENT;
134 void* res = NBalloc::Malloc(bigSize);
135 void* alignedPtr = (void*)NBalloc::Align((size_t)res, alignment);
136 if (alignedPtr != res) {
137 auto oldAllocHeader = (NBalloc::TAllocHeader*)res - 1;
138 auto newAllocHeader = (NBalloc::TAllocHeader*)alignedPtr - 1;
139 void* block = oldAllocHeader->Block;
140 newAllocHeader->Encode(block, size, NBalloc::ALIVE_SIGNATURE);
141 }
142 *memptr = alignedPtr;
143 return 0;
144#endif
145}
146
147void* operator new(size_t size, const std::nothrow_t&) OP_THROWNOTHING {
148#if defined(Y_COVER_PTR)

Callers 3

aligned_allocFunction · 0.70
GetAlignedMemoryFunction · 0.50
aligned_mallocFunction · 0.50

Calls 4

mallocFunction · 0.70
MallocFunction · 0.70
AlignFunction · 0.50
EncodeMethod · 0.45

Tested by

no test coverage detected