Skip to content

Instantly share code, notes, and snippets.

@chadaustin
Created October 29, 2014 22:54
Show Gist options
  • Save chadaustin/e544be3849bc47f2c0a4 to your computer and use it in GitHub Desktop.
Save chadaustin/e544be3849bc47f2c0a4 to your computer and use it in GitHub Desktop.
#include <new>
#include <cstdlib>
// malloc cannot fail on Emscripten, so don't even bother checking.
// We also know that `malloc(0)` will return a non-null pointer, so
// don't check that `count` is positive..
__attribute__((__always_inline__)) void* operator new(std::size_t count) {
return std::malloc(count);
}
__attribute__((__always_inline__)) void* operator new[](std::size_t count) {
return std::malloc(count);
}
__attribute__((__always_inline__)) void* operator new(std::size_t count, const std::nothrow_t&) {
return std::malloc(count);
}
__attribute__((__always_inline__)) void* operator new[](std::size_t count, const std::nothrow_t&) {
return std::malloc(count);
}
__attribute__((__always_inline__)) void operator delete(void* ptr) noexcept {
std::free(ptr);
}
__attribute__((__always_inline__)) void operator delete[](void* ptr) noexcept {
std::free(ptr);
}
__attribute__((__always_inline__)) void operator delete(void* ptr, const std::nothrow_t&) noexcept {
std::free(ptr);
}
__attribute__((__always_inline__)) void operator delete[](void* ptr, const std::nothrow_t&) noexcept {
std::free(ptr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment