MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / operator_new_aligned_impl

Function operator_new_aligned_impl

system/lib/libcxx/src/new.cpp:117–135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

115# if _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION
116
117static void* operator_new_aligned_impl(std::size_t size, std::align_val_t alignment) {
118 if (size == 0)
119 size = 1;
120 if (static_cast<size_t>(alignment) < sizeof(void*))
121 alignment = std::align_val_t(sizeof(void*));
122
123 // Try allocating memory. If allocation fails and there is a new_handler,
124 // call it to try free up memory, and try again until it succeeds, or until
125 // the new_handler decides to terminate.
126 void* p;
127 while ((p = std::__libcpp_aligned_alloc(static_cast<std::size_t>(alignment), size)) == nullptr) {
128 std::new_handler nh = std::get_new_handler();
129 if (nh)
130 nh();
131 else
132 break;
133 }
134 return p;
135}
136
137_LIBCPP_OVERRIDABLE_FUNCTION(void*, operator new, (std::size_t size, std::align_val_t alignment)) _THROW_BAD_ALLOC {
138 void* p = operator_new_aligned_impl(size, alignment);

Callers 3

operator newFunction · 0.70
operator new[]Function · 0.70

Calls 3

__libcpp_aligned_allocFunction · 0.85
get_new_handlerFunction · 0.70
align_val_tEnum · 0.50

Tested by

no test coverage detected