aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ring.h
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2015-02-23 02:54:41 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2015-02-23 02:54:41 +0100
commitb40fe867e021bc365df1a904c2b1ed2068208f13 (patch)
tree94fa618661bec5e25980bde2cb01249c5c3e2c35 /src/ring.h
parent611bb221a96e50fd8561886ec34d8a42e136b5ce (diff)
downloadsciteco-b40fe867e021bc365df1a904c2b1ed2068208f13.tar.gz
implemented to undo stack memory limiting
* acts as a safe-guard against uninterrupted infinite loops or other operations that are costly to undo in interactive mode. If we're out of memory, it is usually too late to react properly. This implementation tries to avoid OOMs due to SciTECO behaviour. We cannot fully exclude the chance of an OOM error. * The undo stack size is only approximated using the UndoToken::get_size() method. Other ways to measure the exact amount of allocated heap (including size fields in every heap object or using sbrk(0) and similar) are either costly in terms of memory or platform-specific. This implementation does not need any additional memory per heap object or undo token but exploits the fact that undo tokens are virtual already. The size of an undo token is determined at compile time. * Default memory limit of 500mb should be OK for most people. * The current limit can be queried with "2EJ" and set with <x>,2EJ. This also works interactively (a bit tricky!) * Limiting can be disabled. In this case, undo token processing is a bit faster. * closes #3
Diffstat (limited to 'src/ring.h')
-rw-r--r--src/ring.h11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/ring.h b/src/ring.h
index 5fe4082..0aa12f0 100644
--- a/src/ring.h
+++ b/src/ring.h
@@ -40,12 +40,12 @@ namespace SciTECO {
class Buffer : private IOView {
TAILQ_ENTRY(Buffer) buffers;
- class UndoTokenClose : public UndoToken {
+ class UndoTokenClose : public UndoTokenWithSize<UndoTokenClose> {
Buffer *buffer;
public:
UndoTokenClose(Buffer *_buffer)
- : UndoToken(), buffer(_buffer) {}
+ : buffer(_buffer) {}
void run(void);
};
@@ -148,6 +148,13 @@ extern class Ring {
}
void run(void);
+
+ gsize
+ get_size(void) const
+ {
+ return buffer ? sizeof(*this) + sizeof(*buffer)
+ : sizeof(*this);
+ }
};
TAILQ_HEAD(Head, Buffer) head;