New.h 805 B

12345678910111213141516171819202122232425262728293031323334
  1. #pragma once
  2. #include "il2cpp-config.h"
  3. #if IL2CPP_TARGET_WINDOWS || IL2CPP_TARGET_XBOXONE
  4. #include <malloc.h>
  5. #else
  6. #include <stdlib.h>
  7. #endif
  8. #include <new>
  9. inline void* operator new(size_t size, int alignment)
  10. {
  11. void* result = NULL;
  12. #if IL2CPP_TARGET_WINDOWS || IL2CPP_TARGET_XBOXONE
  13. result = _aligned_malloc(size, alignment);
  14. #elif IL2CPP_TARGET_ANDROID || IL2CPP_TARGET_PSP2
  15. result = memalign(alignment, size);
  16. #else
  17. if (posix_memalign(&result, size, alignment))
  18. result = NULL;
  19. #endif
  20. if (!result)
  21. throw std::bad_alloc();
  22. return result;
  23. }
  24. #if IL2CPP_TARGET_WINDOWS || IL2CPP_TARGET_XBOXONE // Visual C++ warns if new is overridden but delete is not.
  25. inline void operator delete(void* ptr, int alignment) throw ()
  26. {
  27. free(ptr);
  28. }
  29. #endif