malloc.cpp 885 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "malloc.h"
  2. #include <util/system/compiler.h>
  3. #include <util/system/platform.h>
  4. #include <stdlib.h>
  5. ////////////////////////////////////////////////////////////////////////////////
  6. extern "C" Y_WEAK size_t nallocx(size_t size, int /*flags*/) noexcept
  7. {
  8. return size;
  9. }
  10. #if defined(__ANDROID__)
  11. extern "C" Y_WEAK size_t malloc_usable_size(const void* /*ptr*/)
  12. {
  13. return 0;
  14. }
  15. #elif !defined(_win_)
  16. extern "C" Y_WEAK size_t malloc_usable_size(void* /*ptr*/) noexcept
  17. {
  18. return 0;
  19. }
  20. #endif
  21. void* aligned_malloc(size_t size, size_t alignment)
  22. {
  23. #if defined(_win_)
  24. return _aligned_malloc(size, alignment);
  25. #elif defined(_darwin_) || defined(_linux_)
  26. void* ptr = nullptr;
  27. ::posix_memalign(&ptr, alignment, size);
  28. return ptr;
  29. #else
  30. # error Unsupported platform
  31. #endif
  32. }
  33. ////////////////////////////////////////////////////////////////////////////////