From bdc467e9f8d7c72d912eb7fdc434b3a14b52d901 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 10 Jun 2019 03:31:18 +0300 Subject: Add chat command /trimmemory for force trim freed memory --- src/actions/commands.h | 1 + src/enums/input/inputaction.h | 1 + src/input/inputactionmap.h | 6 ++++++ src/progs/dyecmd/actions/commands.cpp | 1 + src/progs/manaplus/actions/commands.cpp | 15 +++++++++++++++ 5 files changed, 24 insertions(+) (limited to 'src') 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 + #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 -- cgit v1.2.3-60-g2f50