malloc.cpp 769 B

1234567891011121314151617181920212223242526272829303132333435
  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. #ifndef _win_
  11. extern "C" Y_WEAK size_t malloc_usable_size(void* /*ptr*/) noexcept
  12. {
  13. return 0;
  14. }
  15. #endif
  16. void* aligned_malloc(size_t size, size_t alignment)
  17. {
  18. #if defined(_win_)
  19. return _aligned_malloc(size, alignment);
  20. #elif defined(_darwin_) || defined(_linux_)
  21. void* ptr = nullptr;
  22. ::posix_memalign(&ptr, alignment, size);
  23. return ptr;
  24. #else
  25. # error Unsupported platform
  26. #endif
  27. }
  28. ////////////////////////////////////////////////////////////////////////////////