MCPcopy Create free account
hub / github.com/apache/arrow / AllocateAligned

Method AllocateAligned

cpp/src/arrow/memory_pool.cc:303–335  ·  view source on GitHub ↗

Allocate memory according to the alignment requirements for Arrow (as of May 2016 64 bytes)

Source from the content-addressed store, hash-verified

301 // Allocate memory according to the alignment requirements for Arrow
302 // (as of May 2016 64 bytes)
303 static Status AllocateAligned(int64_t size, int64_t alignment, uint8_t** out) {
304 if (size == 0) {
305 *out = memory_pool::internal::kZeroSizeArea;
306 return Status::OK();
307 }
308#ifdef _WIN32
309 // Special code path for Windows
310 *out = reinterpret_cast<uint8_t*>(
311 _aligned_malloc(static_cast<size_t>(size), static_cast<size_t>(alignment)));
312 if (!*out) {
313 return Status::OutOfMemory("malloc of size ", size, " failed");
314 }
315#elif defined(sun) || defined(__sun)
316 *out = reinterpret_cast<uint8_t*>(
317 memalign(static_cast<size_t>(alignment), static_cast<size_t>(size)));
318 if (!*out) {
319 return Status::OutOfMemory("malloc of size ", size, " failed");
320 }
321#else
322 const int result =
323 posix_memalign(reinterpret_cast<void**>(out), static_cast<size_t>(alignment),
324 static_cast<size_t>(size));
325 if (result == ENOMEM) {
326 return Status::OutOfMemory("malloc of size ", size, " failed");
327 }
328
329 if (result == EINVAL) {
330 return Status::Invalid("invalid alignment parameter: ",
331 static_cast<size_t>(alignment));
332 }
333#endif
334 return Status::OK();
335 }
336
337 static Status ReallocateAligned(int64_t old_size, int64_t new_size, int64_t alignment,
338 uint8_t** ptr) {

Callers

nothing calls this directly

Calls 3

OutOfMemoryFunction · 0.85
OKFunction · 0.70
InvalidFunction · 0.70

Tested by

no test coverage detected