// Static variables struct evl_heap heap_manager::s_runtime_heap; bool heap_manager::s_use_evl = false; // Flag used in global new/delete to switch between Linux and EVL heaps size_t heap_manager::s_init_bytes = 2147483648; // 2GB /////////////////////////////////////////////////////////////////////////////// void* heap_manager::alloc_block(size_t bytes) { void* data = evl_alloc_block(&s_runtime_heap, bytes); if (data == NULL) { // Switch back to Linux heap to avoid infinite alloc loop s_use_evl = false; throw(std::runtime_error("Error allocating a block on the EVL heap")); } return data; } /////////////////////////////////////////////////////////////////////////////// void heap_manager::free_block(void* block) { int ret = evl_free_block(&s_runtime_heap, block); if (ret < 0) { sfhm::rtString msg; msg.Format("%s:%d: Error freeing a block on the EVL heap", __FILE__, __LINE__); throw(std::system_error(ret, std::generic_category(), msg)); } } /////////////////////////////////////////////////////////////////////////////// void heap_manager::prefault() { char *dummy = (char*)alloc_block(s_init_bytes); for (size_t i = 0; i < s_init_bytes; i += sysconf(_SC_PAGESIZE)) dummy[i] = 1; free_block(dummy); }