How might I overload the “new” operator to allocate memory from a secondary memory device?
问题 I am looking for a syntax to allocate memory from a secondary memory device and not from the default heap. How can i implement it? Using malloc() would by default take it from heap... Surely there must be another way! 回答1: #include <new> void* operator new(std::size_t size) throw(std::bad_alloc) { while (true) { void* result = allocate_from_some_other_source(size); if (result) return result; std::new_handler nh = std::set_new_handler(0); std::set_new_handler(nh); // put it back // this is