aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/undo.cpp
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2016-11-20 09:00:50 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2016-11-20 18:18:36 +0100
commitb7ff56db631be7416cf228dff89cb23d753e4ec8 (patch)
tree9a23fad0141ef7d693f6920256e4b83e8f699c03 /src/undo.cpp
parent29200089d2728b320d9862758ce2493e80116549 (diff)
downloadsciteco-b7ff56db631be7416cf228dff89cb23d753e4ec8.tar.gz
fixed glib warnings about using g_mem_set_vtable() and revised memory limiting
* we were basing the glib allocators on throwing std::bad_alloc just like the C++ operators. However, this always was unsafe since we were throwing exceptions across plain-C frames (Glib). Also, the memory vtable has been deprecated in Glib, resulting in ugly warnings. * Instead, we now let the C++ new/delete operators work like Glib by basing them on g_malloc/g_slice. This means they will assert and the application will terminate abnormally in case of OOM. OOMs cannot be handled properly anyway, so it is more important to have a good memory limiting mechanism. * Memory limiting has been completely revised. Instead of approximating undo stack sizes using virtual methods (which is unprecise and comes with a performance penalty), we now use a common base class SciTECO::Object to count the memory required by all objects allocated within SciTECO. This is less precise than using global replacement new/deletes which would allow us to control allocations in all C++ code including Scintilla, but they are only supported as of C++14 (GCC 5) and adding compile-time checks would be cumbersome. In any case, we're missing Glib allocations (esp. strings). * As a platform-specific extension, on Linux/glibc we use mallinfo() to count the exact memory usage of the process. On Windows, we use GetProcessMemoryInfo() -- the latter implementation is currently UNTESTED. * We use g_malloc() for new/delete operators when there is malloc_trim() since g_slice does not free heap chunks properly (probably does its own mmap()ing), rendering malloc_trim() ineffective. We've also benchmarked g_slice on Linux/glib (malloc_trim() shouldn't be available elsewhere) and found that it brings no significant performance benefit. On all other platforms, we use g_slice since it is assumed that it at least does not hurt. The new g_slice based allocators should be tested on MSVCRT since I assume that they bring a significant performance benefit on Windows. * Memory limiting does now work in batch mode as well and is still enabled by default. * The old UndoTokenWithSize CRTP hack could be removed. UndoStack operations should be a bit faster now. But on the other hand, there will be an overhead due to repeated memory limit checking on every processed character.
Diffstat (limited to 'src/undo.cpp')
-rw-r--r--src/undo.cpp45
1 files changed, 0 insertions, 45 deletions
diff --git a/src/undo.cpp b/src/undo.cpp
index e189e23..4593fdc 100644
--- a/src/undo.cpp
+++ b/src/undo.cpp
@@ -29,12 +29,8 @@
#include "sciteco.h"
#include "cmdline.h"
-#include "interface.h"
-#include "error.h"
#include "undo.h"
-#define SIZE_TO_MB(SIZE) ((gdouble)(SIZE))/(1024*1024)
-
namespace SciTECO {
//#define DEBUG
@@ -42,29 +38,6 @@ namespace SciTECO {
UndoStack undo;
void
-UndoStack::set_memory_limit(gsize new_limit)
-{
- if (new_limit) {
- if (!memory_limit) {
- /* memory_usage outdated - recalculate */
- UndoToken *token;
-
- memory_usage = 0;
- SLIST_FOREACH(token, &head, tokens)
- memory_usage += token->get_size();
- }
-
- if (memory_usage > new_limit)
- throw Error("Cannot set undo memory limit (%gmb): "
- "Current stack too large (%gmb).",
- SIZE_TO_MB(new_limit),
- SIZE_TO_MB(memory_usage));
- }
-
- push_var(memory_limit) = new_limit;
-}
-
-void
UndoStack::push(UndoToken *token)
{
/*
@@ -74,19 +47,6 @@ UndoStack::push(UndoToken *token)
*/
g_assert(enabled == true);
- if (memory_limit) {
- gsize token_size = token->get_size();
-
- if (memory_usage + token_size > memory_limit) {
- delete token;
- throw Error("Undo stack memory limit (%gmb) exceeded. "
- "See <EJ> command.",
- SIZE_TO_MB(memory_limit));
- }
-
- memory_usage += token_size;
- }
-
#ifdef DEBUG
g_printf("UNDO PUSH %p\n", token);
#endif
@@ -103,9 +63,6 @@ UndoStack::pop(gint pc)
g_printf("UNDO POP %p\n", top);
fflush(stdout);
#endif
-
- if (memory_limit)
- memory_usage -= top->get_size();
top->run();
SLIST_REMOVE_HEAD(&head, tokens);
@@ -122,8 +79,6 @@ UndoStack::clear(void)
SLIST_REMOVE_HEAD(&head, tokens);
delete cur;
}
-
- memory_usage = 0;
}
UndoStack::~UndoStack()