GstMemory is a lightweight refcounted object that wraps a region of memory.
They are typically used to manage the data of a Buffer.
A GstMemory object has an allocated region of memory of maxsize. The maximum size does not change during the lifetime of the memory object. The memory also has an offset and size property that specifies the valid range of memory in the allocated region.
Memory is usually created by allocators with a alloc method call. When
null
is used as the allocator, the default allocator will be used.
New allocators can be registered with register. Allocators are identified by name and can be retrieved with find. set_default can be used to change the default allocator.
New memory can be created with new_wrapped that wraps the memory allocated elsewhere.
Refcounting of the memory block is performed with gst_memory_ref
and gst_memory_unref
.
The size of the memory can be retrieved and changed with get_sizes and resize respectively.
Getting access to the data of the memory is performed with map. The call will return a pointer to offset bytes into the region of memory. After the memory access is completed, unmap should be called.
Memory can be copied with copy, which will return a writable copy. share will create a new memory block that shares the memory with an existing memory block at a custom offset and with a custom size.
Memory can be efficiently merged when is_span returns true
.