Package io.github.jwharm.javagi.gobject
Class InstanceCache
java.lang.Object
io.github.jwharm.javagi.gobject.InstanceCache
Caches Proxy instances so the same instance is used for the same memory
address.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Proxy
get
(MemorySegment address, Function<MemorySegment, ? extends Proxy> fallback, boolean cache) Get aProxy
object for the provided native memory address.static Proxy
getForType
(MemorySegment address, Function<MemorySegment, ? extends Proxy> fallback, boolean cache) Get aProxy
object for the provided native memory address.static Proxy
getForTypeClass
(MemorySegment address, Function<MemorySegment, ? extends Proxy> fallback, boolean ignored) Get aProxy
object for the provided native memory address of a TypeClass.static Proxy
put
(MemorySegment address, Proxy object) Add the new GObject instance to the cache.
-
Constructor Details
-
InstanceCache
public InstanceCache()
-
-
Method Details
-
getForType
public static Proxy getForType(MemorySegment address, Function<MemorySegment, ? extends Proxy> fallback, boolean cache) Get aProxy
object for the provided native memory address. If a Proxy object does not yet exist for this address, a new Proxy object is instantiated and added to the cache. The type of the Proxy object is read from the gtype field of the native instance. Invalid references are removed from the cache using a GObject toggle reference.- Parameters:
address
- memory address of the native objectfallback
- fallback constructor to use when the type is not found in the TypeCache- Returns:
- a Proxy instance for the provided memory address
-
getForTypeClass
public static Proxy getForTypeClass(MemorySegment address, Function<MemorySegment, ? extends Proxy> fallback, boolean ignored) Get aProxy
object for the provided native memory address of a TypeClass. If a Proxy object does not yet exist for this address, a new Proxy object is instantiated and added to the cache. The type of the Proxy object is read from the gtype field of the native TypeClass.- Parameters:
address
- memory address of the native objectfallback
- fallback constructor to use when the type is not found in the TypeCacheignored
- ignored- Returns:
- a Proxy instance for the provided memory address
-
get
public static Proxy get(MemorySegment address, Function<MemorySegment, ? extends Proxy> fallback, boolean cache) Get aProxy
object for the provided native memory address. If a Proxy object does not yet exist for this address, a new Proxy object is instantiated and added to the cache. Invalid references are removed from the cache using a GObject toggle reference.- Parameters:
address
- memory address of the native objectfallback
- constructor for the Java proxy object- Returns:
- a Proxy instance for the provided memory address
-
put
Add the new GObject instance to the cache. Floating references are sunk, and a toggle reference is installed.- Parameters:
address
- the memory address of the native instanceobject
- the GObject instance- Returns:
- the cached GObject instance
-