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.MemoryMonitorIF; 26 27 private import gio.MemoryMonitorIF; 28 private import gio.c.functions; 29 public import gio.c.types; 30 private import gobject.ObjectG; 31 private import gobject.Signals; 32 private import std.algorithm; 33 34 35 /** 36 * #GMemoryMonitor will monitor system memory and suggest to the application 37 * when to free memory so as to leave more room for other applications. 38 * It is implemented on Linux using the [Low Memory Monitor](https://gitlab.freedesktop.org/hadess/low-memory-monitor/) 39 * ([API documentation](https://hadess.pages.freedesktop.org/low-memory-monitor/)). 40 * 41 * There is also an implementation for use inside Flatpak sandboxes. 42 * 43 * Possible actions to take when the signal is received are: 44 * - Free caches 45 * - Save files that haven't been looked at in a while to disk, ready to be reopened when needed 46 * - Run a garbage collection cycle 47 * - Try and compress fragmented allocations 48 * - Exit on idle if the process has no reason to stay around 49 * - Call [`malloc_trim(3)`](man:malloc_trim) to return cached heap pages to 50 * the kernel (if supported by your libc) 51 * 52 * Note that some actions may not always improve system performance, and so 53 * should be profiled for your application. `malloc_trim()`, for example, may 54 * make future heap allocations slower (due to releasing cached heap pages back 55 * to the kernel). 56 * 57 * See #GMemoryMonitorWarningLevel for details on the various warning levels. 58 * 59 * |[<!-- language="C" --> 60 * static void 61 * warning_cb (GMemoryMonitor *m, GMemoryMonitorWarningLevel level) 62 * { 63 * g_debug ("Warning level: %d", level); 64 * if (warning_level > G_MEMORY_MONITOR_WARNING_LEVEL_LOW) 65 * drop_caches (); 66 * } 67 * 68 * static GMemoryMonitor * 69 * monitor_low_memory (void) 70 * { 71 * GMemoryMonitor *m; 72 * m = g_memory_monitor_dup_default (); 73 * g_signal_connect (G_OBJECT (m), "low-memory-warning", 74 * G_CALLBACK (warning_cb), NULL); 75 * return m; 76 * } 77 * ]| 78 * 79 * Don't forget to disconnect the #GMemoryMonitor::low-memory-warning 80 * signal, and unref the #GMemoryMonitor itself when exiting. 81 * 82 * Since: 2.64 83 */ 84 public interface MemoryMonitorIF{ 85 /** Get the main Gtk struct */ 86 public GMemoryMonitor* getMemoryMonitorStruct(bool transferOwnership = false); 87 88 /** the main Gtk struct as a void* */ 89 protected void* getStruct(); 90 91 92 /** */ 93 public static GType getType() 94 { 95 return g_memory_monitor_get_type(); 96 } 97 98 /** 99 * Gets a reference to the default #GMemoryMonitor for the system. 100 * 101 * Returns: a new reference to the default #GMemoryMonitor 102 * 103 * Since: 2.64 104 */ 105 public static MemoryMonitorIF dupDefault() 106 { 107 auto __p = g_memory_monitor_dup_default(); 108 109 if(__p is null) 110 { 111 return null; 112 } 113 114 return ObjectG.getDObject!(MemoryMonitorIF)(cast(GMemoryMonitor*) __p, true); 115 } 116 117 /** 118 * Emitted when the system is running low on free memory. The signal 119 * handler should then take the appropriate action depending on the 120 * warning level. See the #GMemoryMonitorWarningLevel documentation for 121 * details. 122 * 123 * Params: 124 * level = the #GMemoryMonitorWarningLevel warning level 125 * 126 * Since: 2.64 127 */ 128 gulong addOnLowMemoryWarning(void delegate(GMemoryMonitorWarningLevel, MemoryMonitorIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0); 129 }