diff options
author | babenko <babenko@yandex-team.com> | 2022-11-03 08:56:11 +0300 |
---|---|---|
committer | babenko <babenko@yandex-team.com> | 2022-11-03 08:56:11 +0300 |
commit | 3910880160a4aaae4c26adeea4fe525e91856737 (patch) | |
tree | b3c739692b49f1463cb62ddc7a0069b15fa0d516 /library/cpp/yt/malloc/malloc.cpp | |
parent | a0d00502b1c5789adf896de18dd4c25b097a098d (diff) | |
download | ydb-3910880160a4aaae4c26adeea4fe525e91856737.tar.gz |
Introduce aligned_malloc; drop more YTAlloc dependencies
Diffstat (limited to 'library/cpp/yt/malloc/malloc.cpp')
-rw-r--r-- | library/cpp/yt/malloc/malloc.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/library/cpp/yt/malloc/malloc.cpp b/library/cpp/yt/malloc/malloc.cpp index 4a35758cab..9a055eaaa0 100644 --- a/library/cpp/yt/malloc/malloc.cpp +++ b/library/cpp/yt/malloc/malloc.cpp @@ -1,9 +1,13 @@ #include "malloc.h" #include <util/system/compiler.h> +#include <util/system/platform.h> + +#include <stdlib.h> //////////////////////////////////////////////////////////////////////////////// +#ifndef _win_ Y_WEAK extern "C" size_t nallocx(size_t size, int /*flags*/) noexcept { return size; @@ -13,5 +17,19 @@ Y_WEAK extern "C" size_t malloc_usable_size(void* /*ptr*/) noexcept { return 0; } +#endif + +void* aligned_malloc(size_t size, size_t alignment) +{ +#if defined(_win_) + return _aligned_malloc(size, alignment); +#elif defined(_darwin_) || defined(_linux_) + void* ptr = nullptr; + ::posix_memalign(&ptr, alignment, size); + return ptr; +#else +# error Unsupported platform +#endif +} //////////////////////////////////////////////////////////////////////////////// |