-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
71 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "memory.h" | ||
|
||
#include <cassert> | ||
#include <iostream> | ||
|
||
namespace dlplan::utils { | ||
static char *extra_memory_padding = nullptr; | ||
|
||
// Save standard out-of-memory handler. | ||
static void (*standard_out_of_memory_handler)() = nullptr; | ||
|
||
static void continuing_out_of_memory_handler() { | ||
release_extra_memory_padding(); | ||
std::cout << "Failed to allocate memory. Released extra memory padding." << std::endl; | ||
} | ||
|
||
void reserve_extra_memory_padding(int memory_in_mb) { | ||
assert(!extra_memory_padding); | ||
extra_memory_padding = new char[memory_in_mb * 1024 * 1024]; | ||
standard_out_of_memory_handler = std::set_new_handler(continuing_out_of_memory_handler); | ||
} | ||
|
||
void release_extra_memory_padding() { | ||
assert(extra_memory_padding); | ||
delete[] extra_memory_padding; | ||
extra_memory_padding = nullptr; | ||
assert(standard_out_of_memory_handler); | ||
std::set_new_handler(standard_out_of_memory_handler); | ||
} | ||
|
||
bool extra_memory_padding_is_reserved() { | ||
return extra_memory_padding; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,26 @@ | ||
#ifndef DLPLAN_SRC_UTILS_MEMORY_H | ||
#define DLPLAN_SRC_UTILS_MEMORY_H | ||
|
||
#include <memory> | ||
#include <utility> | ||
|
||
namespace dlplan::utils { | ||
|
||
/** | ||
* Uses swap-trick to free memory of container. | ||
*/ | ||
template<typename CONTAINER_TYPE> | ||
void free_memory(CONTAINER_TYPE& container) { | ||
CONTAINER_TYPE().swap(container); | ||
} | ||
/* | ||
Taken from Fast-Downward (https://www.fast-downward.org/) | ||
Reserve some memory that we can release and be able to continue | ||
afterwards, once we hit the memory limit. Due to memory fragmentation | ||
the planner often doesn't have enough memory to continue if we don't | ||
reserve enough memory. For CEGAR heuristics reserving 75 MB worked | ||
best. | ||
The interface assumes a single user. It is not possible for two parts | ||
of the planner to reserve extra memory padding at the same time. | ||
*/ | ||
extern void reserve_extra_memory_padding(int memory_in_mb); | ||
extern void release_extra_memory_padding(); | ||
extern bool extra_memory_padding_is_reserved(); | ||
} | ||
|
||
#endif |