summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2019-06-10 03:31:18 +0300
committerAndrei Karas <akaras@inbox.ru>2019-06-10 03:31:18 +0300
commitbdc467e9f8d7c72d912eb7fdc434b3a14b52d901 (patch)
tree0b8a6f6a945314c05f66957ac2a6dc2c9b6b2664
parent96b6acb72bab198d278919daa11390c573341647 (diff)
downloadplus-bdc467e9f8d7c72d912eb7fdc434b3a14b52d901.tar.gz
plus-bdc467e9f8d7c72d912eb7fdc434b3a14b52d901.tar.bz2
plus-bdc467e9f8d7c72d912eb7fdc434b3a14b52d901.tar.xz
plus-bdc467e9f8d7c72d912eb7fdc434b3a14b52d901.zip
Add chat command /trimmemory for force trim freed memory
-rwxr-xr-xconfigure.ac1
-rw-r--r--src/actions/commands.h1
-rw-r--r--src/enums/input/inputaction.h1
-rw-r--r--src/input/inputactionmap.h6
-rw-r--r--src/progs/dyecmd/actions/commands.cpp1
-rw-r--r--src/progs/manaplus/actions/commands.cpp15
6 files changed, 25 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index 7bdca2844..a333ab97e 100755
--- a/configure.ac
+++ b/configure.ac
@@ -235,6 +235,7 @@ AC_FUNC_MMAP
AC_CHECK_FUNCS([atexit floor getcwd gethostbyname memset mkdir select socket])
AC_CHECK_FUNCS([clock_gettime dup2 gettimeofday memchr memmove pow putenv])
AC_CHECK_FUNCS([realpath setenv setlocale sqrt strchr munmap])
+AC_CHECK_FUNCS([malloc_trim])
#AC_CHECK_HEADER_STDBOOL
AC_CHECK_HEADERS([libintl.h limits.h sys/param.h sys/time.h wchar.h])
diff --git a/src/actions/commands.h b/src/actions/commands.h
index 80ac78a4e..3b675c848 100644
--- a/src/actions/commands.h
+++ b/src/actions/commands.h
@@ -163,6 +163,7 @@ namespace Actions
decHandler(movePriorityAttackUp);
decHandler(movePriorityAttackDown);
decHandler(addSkillShortcut);
+ decHandler(trimMemory);
} // namespace Actions
#undef decHandler
diff --git a/src/enums/input/inputaction.h b/src/enums/input/inputaction.h
index c21506729..a1689e7a8 100644
--- a/src/enums/input/inputaction.h
+++ b/src/enums/input/inputaction.h
@@ -710,6 +710,7 @@ enumStart(InputAction)
PET_UNEQUIP,
ADD_SKILL_SHORTCUT,
WINDOW_CLAN,
+ TRIM_MEMORY,
TOTAL
}
enumEnd(InputAction);
diff --git a/src/input/inputactionmap.h b/src/input/inputactionmap.h
index f215a403b..ba8830130 100644
--- a/src/input/inputactionmap.h
+++ b/src/input/inputactionmap.h
@@ -5966,6 +5966,12 @@ static const InputActionData inputActionData
"clanwindow|clan",
UseArgs_false,
Protected_false},
+ {"keyTrimMemory",
+ defaultAction(&Actions::trimMemory),
+ InputCondition::KEY_DOWN | InputCondition::INGAME,
+ "trim|trimmemory|memorytrim",
+ UseArgs_false,
+ Protected_true},
};
#undef defaultAction
diff --git a/src/progs/dyecmd/actions/commands.cpp b/src/progs/dyecmd/actions/commands.cpp
index 217aa5b53..5ee4d3089 100644
--- a/src/progs/dyecmd/actions/commands.cpp
+++ b/src/progs/dyecmd/actions/commands.cpp
@@ -163,5 +163,6 @@ impHandlerVoid(moveAttackDown)
impHandlerVoid(movePriorityAttackUp)
impHandlerVoid(movePriorityAttackDown)
impHandlerVoid(addSkillShortcut)
+impHandlerVoid(trimMemory)
} // namespace Actions
diff --git a/src/progs/manaplus/actions/commands.cpp b/src/progs/manaplus/actions/commands.cpp
index ff24d6bc3..57f5125b2 100644
--- a/src/progs/manaplus/actions/commands.cpp
+++ b/src/progs/manaplus/actions/commands.cpp
@@ -85,6 +85,8 @@
#include "utils/parameters.h"
#include "utils/process.h"
+#include <malloc.h>
+
#include "debug.h"
namespace Actions
@@ -2200,4 +2202,17 @@ impHandler(addSkillShortcut)
return true;
}
+impHandler0(trimMemory)
+{
+#ifdef HAVE_MALLOC_TRIM
+ malloc_trim(0);
+#else
+ localChatTab->chatLog(_("Trim memory not supported"),
+ ChatMsgType::BY_SERVER,
+ IgnoreRecord_false,
+ TryRemoveColors_true);
+#endif
+ return true;
+}
+
} // namespace Actions