Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed Aug 20, 2024
1 parent 140e7ff commit 98566b6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from setuptools import setup, find_packages, Extension
from setuptools.command.build_ext import build_ext

__version__ = "0.3.26"
__version__ = "0.3.27"
HERE = Path(__file__).resolve().parent


Expand Down
18 changes: 13 additions & 5 deletions src/utils/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
namespace dlplan::utils {
static char *extra_memory_padding = nullptr;

// Save standard out-of-memory handler.
static void (*standard_out_of_memory_handler)() = nullptr;
// Save default out-of-memory handler.
static void (*default_out_of_memory_handler)() = nullptr;
// Save current out-of-memory handler.
static void (*current_out_of_memory_handler)() = nullptr;

static void continuing_out_of_memory_handler() {
release_extra_memory_padding();
Expand All @@ -16,19 +18,25 @@ static void continuing_out_of_memory_handler() {

void reserve_extra_memory_padding(int memory_in_mb) {
assert(!extra_memory_padding);
assert(!current_out_of_memory_handler);

extra_memory_padding = new char[memory_in_mb * 1024 * 1024];
standard_out_of_memory_handler = std::set_new_handler(continuing_out_of_memory_handler);
std::set_new_handler(continuing_out_of_memory_handler);
current_out_of_memory_handler = continuing_out_of_memory_handler;
}

void release_extra_memory_padding() {
assert(extra_memory_padding);
assert(current_out_of_memory_handler);

delete[] extra_memory_padding;
extra_memory_padding = nullptr;
assert(standard_out_of_memory_handler);
std::set_new_handler(standard_out_of_memory_handler);
std::set_new_handler(default_out_of_memory_handler);
current_out_of_memory_handler = nullptr;
}

bool extra_memory_padding_is_reserved() {
return extra_memory_padding;
}

}
2 changes: 2 additions & 0 deletions src/utils/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <memory>
#include <utility>
#include <vector>

namespace dlplan::utils {

Expand All @@ -21,6 +22,7 @@ namespace dlplan::utils {
extern void reserve_extra_memory_padding(int memory_in_mb);
extern void release_extra_memory_padding();
extern bool extra_memory_padding_is_reserved();

}

#endif

0 comments on commit 98566b6

Please sign in to comment.