// Package gio was automatically generated by github.com/bnema/puregotk DO NOT EDIT package gio import ( "structs" "unsafe" "github.com/ebitengine/purego" "github.com/bnema/puregotk/pkg/core" "github.com/bnema/puregotk/v4/gobject/types" ) // The virtual function table for #GMemoryMonitor. type MemoryMonitorInterface struct { _ structs.HostLayout GIface uintptr xLowMemoryWarning uintptr } func (x *MemoryMonitorInterface) GoPointer() uintptr { return uintptr(unsafe.Pointer(x)) } // OverrideLowMemoryWarning sets the "low_memory_warning" callback function. // the virtual function pointer for the // // #GMemoryMonitor::low-memory-warning signal. func (x *MemoryMonitorInterface) OverrideLowMemoryWarning(cb func(MemoryMonitor, MemoryMonitorWarningLevel)) { if cb == nil { x.xLowMemoryWarning = 0 } else { x.xLowMemoryWarning = purego.NewCallback(func(MonitorVarp uintptr, LevelVarp MemoryMonitorWarningLevel) { cb(&MemoryMonitorBase{Ptr: MonitorVarp}, LevelVarp) }) } } // GetLowMemoryWarning gets the "low_memory_warning" callback function. // the virtual function pointer for the // // #GMemoryMonitor::low-memory-warning signal. func (x *MemoryMonitorInterface) GetLowMemoryWarning() func(MemoryMonitor, MemoryMonitorWarningLevel) { if x.xLowMemoryWarning == 0 { return nil } var rawCallback func(MonitorVarp uintptr, LevelVarp MemoryMonitorWarningLevel) purego.RegisterFunc(&rawCallback, x.xLowMemoryWarning) return func(MonitorVar MemoryMonitor, LevelVar MemoryMonitorWarningLevel) { rawCallback(MonitorVar.GoPointer(), LevelVar) } } // `GMemoryMonitor` will monitor system memory and suggest to the application // when to free memory so as to leave more room for other applications. // It is implemented on Linux using the // [Low Memory Monitor](https://gitlab.freedesktop.org/hadess/low-memory-monitor/) // ([API documentation](https://hadess.pages.freedesktop.org/low-memory-monitor/)). // // There is also an implementation for use inside Flatpak sandboxes. // // Possible actions to take when the signal is received are: // // - Free caches // - Save files that haven’t been looked at in a while to disk, ready to be reopened when needed // - Run a garbage collection cycle // - Try and compress fragmented allocations // - Exit on idle if the process has no reason to stay around // - Call [`malloc_trim(3)`](man:malloc_trim(3)) to return cached heap pages to // the kernel (if supported by your libc) // // Note that some actions may not always improve system performance, and so // should be profiled for your application. `malloc_trim()`, for example, may // make future heap allocations slower (due to releasing cached heap pages back // to the kernel). // // See [type@Gio.MemoryMonitorWarningLevel] for details on the various warning // levels. // // ```c // static void // warning_cb (GMemoryMonitor *m, GMemoryMonitorWarningLevel level) // // { // g_debug ("Warning level: %d", level); // if (warning_level > G_MEMORY_MONITOR_WARNING_LEVEL_LOW) // drop_caches (); // } // // static GMemoryMonitor * // monitor_low_memory (void) // // { // GMemoryMonitor *m; // m = g_memory_monitor_dup_default (); // g_signal_connect (G_OBJECT (m), "low-memory-warning", // G_CALLBACK (warning_cb), NULL); // return m; // } // // ``` // // Don’t forget to disconnect the [signal@Gio.MemoryMonitor::low-memory-warning] // signal, and unref the `GMemoryMonitor` itself when exiting. type MemoryMonitor interface { GoPointer() uintptr SetGoPointer(uintptr) } var xMemoryMonitorGLibType func() types.GType func MemoryMonitorGLibType() types.GType { return xMemoryMonitorGLibType() } type MemoryMonitorBase struct { Ptr uintptr } func (x *MemoryMonitorBase) GoPointer() uintptr { if x == nil { return 0 } return x.Ptr } func (x *MemoryMonitorBase) SetGoPointer(ptr uintptr) { x.Ptr = ptr } const ( // Extension point for memory usage monitoring functionality. // See [Extending GIO](overview.html#extending-gio). MEMORY_MONITOR_EXTENSION_POINT_NAME string = "gio-memory-monitor" ) var xMemoryMonitorDupDefault func() uintptr // Gets a reference to the default #GMemoryMonitor for the system. func MemoryMonitorDupDefault() *MemoryMonitorBase { var cls *MemoryMonitorBase cret := xMemoryMonitorDupDefault() if cret == 0 { return nil } cls = &MemoryMonitorBase{} cls.Ptr = cret return cls } func init() { core.SetPackageName("GIO", "gio-2.0") core.SetSharedLibraries("GIO", []string{"libgio-2.0.so.0"}) var libs []uintptr for _, libPath := range core.GetPaths("GIO") { lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL) if err != nil { panic(err) } libs = append(libs, lib) } core.PuregoSafeRegister(&xMemoryMonitorDupDefault, libs, "g_memory_monitor_dup_default") core.PuregoSafeRegister(&xMemoryMonitorGLibType, libs, "g_memory_monitor_get_type") }