1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gio.MemoryMonitorT; 26 27 public import gio.MemoryMonitorIF; 28 public import gio.c.functions; 29 public import gio.c.types; 30 public import gobject.ObjectG; 31 public import gobject.Signals; 32 public import gtkc.giotypes; 33 public import std.algorithm; 34 35 36 /** 37 * #GMemoryMonitor will monitor system memory and suggest to the application 38 * when to free memory so as to leave more room for other applications. 39 * It is implemented on Linux using the [Low Memory Monitor](https://gitlab.freedesktop.org/hadess/low-memory-monitor/) 40 * ([API documentation](https://hadess.pages.freedesktop.org/low-memory-monitor/)). 41 * 42 * There is also an implementation for use inside Flatpak sandboxes. 43 * 44 * Possible actions to take when the signal is received are: 45 * - Free caches 46 * - Save files that haven't been looked at in a while to disk, ready to be reopened when needed 47 * - Run a garbage collection cycle 48 * - Try and compress fragmented allocations 49 * - Exit on idle if the process has no reason to stay around 50 * 51 * See #GMemoryMonitorWarningLevel for details on the various warning levels. 52 * 53 * |[<!-- language="C" --> 54 * static void 55 * warning_cb (GMemoryMonitor *m, GMemoryMonitorWarningLevel level) 56 * { 57 * g_debug ("Warning level: %d", level); 58 * if (warning_level > G_MEMORY_MONITOR_WARNING_LEVEL_LOW) 59 * drop_caches (); 60 * } 61 * 62 * static GMemoryMonitor * 63 * monitor_low_memory (void) 64 * { 65 * GMemoryMonitor *m; 66 * m = g_memory_monitor_dup_default (); 67 * g_signal_connect (G_OBJECT (m), "low-memory-warning", 68 * G_CALLBACK (warning_cb), NULL); 69 * return m; 70 * } 71 * ]| 72 * 73 * Don't forget to disconnect the #GMemoryMonitor::low-memory-warning 74 * signal, and unref the #GMemoryMonitor itself when exiting. 75 * 76 * Since: 2.64 77 */ 78 public template MemoryMonitorT(TStruct) 79 { 80 /** Get the main Gtk struct */ 81 public GMemoryMonitor* getMemoryMonitorStruct(bool transferOwnership = false) 82 { 83 if (transferOwnership) 84 ownedRef = false; 85 return cast(GMemoryMonitor*)getStruct(); 86 } 87 88 89 /** 90 * Emitted when the system is running low on free memory. The signal 91 * handler should then take the appropriate action depending on the 92 * warning level. See the #GMemoryMonitorWarningLevel documentation for 93 * details. 94 * 95 * Params: 96 * level = the #GMemoryMonitorWarningLevel warning level 97 * 98 * Since: 2.64 99 */ 100 gulong addOnLowMemoryWarning(void delegate(GMemoryMonitorWarningLevel, MemoryMonitorIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 101 { 102 return Signals.connect(this, "low-memory-warning", dlg, connectFlags ^ ConnectFlags.SWAPPED); 103 } 104 }