Memory

GstMemory is a lightweight refcounted object that wraps a region of memory. They are typically used to manage the data of a #GstBuffer.

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 gst.allocator.Allocator.alloc method call. When null is used as the allocator, the default allocator will be used.

New allocators can be registered with gst.allocator.Allocator.register. Allocators are identified by name and can be retrieved with gst.allocator.Allocator.find. gst.allocator.Allocator.setDefault can be used to change the default allocator.

New memory can be created with gst.memory.Memory.newWrapped 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 gst.memory.Memory.getSizes and gst.memory.Memory.resize respectively.

Getting access to the data of the memory is performed with gst.memory.Memory.map. The call will return a pointer to offset bytes into the region of memory. After the memory access is completed, gst.memory.Memory.unmap should be called.

Memory can be copied with gst.memory.Memory.copy, which will return a writable copy. gst.memory.Memory.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 gst.memory.Memory.isSpan returns true.

Members

Functions

copy
gst.memory.Memory copy(ptrdiff_t offset, ptrdiff_t size)

Return a copy of size bytes from mem starting from offset. This copy is guaranteed to be writable. size can be set to -1 to return a copy from offset to the end of the memory region.

getSizes
size_t getSizes(size_t offset, size_t maxsize)

Get the current size, offset and maxsize of mem.

isSpan
bool isSpan(gst.memory.Memory mem2, size_t offset)

Check if mem1 and mem2 share the memory with a common parent memory object and that the memory is contiguous.

isType
bool isType(string memType)

Check if mem if allocated with an allocator for mem_type.

makeMapped
gst.memory.Memory makeMapped(gst.map_info.MapInfo info, gst.types.MapFlags flags)

Create a #GstMemory object that is mapped with flags. If mem is mappable with flags, this function returns the mapped mem directly. Otherwise a mapped copy of mem is returned.

map
bool map(gst.map_info.MapInfo info, gst.types.MapFlags flags)

Fill info with the pointer and sizes of the memory in mem that can be accessed according to flags.

resize
void resize(ptrdiff_t offset, size_t size)

Resize the memory region. mem should be writable and offset + size should be less than the maxsize of mem.

share
gst.memory.Memory share(ptrdiff_t offset, ptrdiff_t size)

Return a shared copy of size bytes from mem starting from offset. No memory copy is performed and the memory region is simply shared. The result is guaranteed to be non-writable. size can be set to -1 to return a shared copy from offset to the end of the memory region.

unmap
void unmap(gst.map_info.MapInfo info)

Release the memory obtained with gst.memory.Memory.map

Static functions

newWrapped
gst.memory.Memory newWrapped(gst.types.MemoryFlags flags, ubyte[] data, size_t maxsize, size_t offset, glib.types.DestroyNotify notify)

Allocate a new memory block that wraps the given data.

Inherited Members

From Boxed

cInstancePtr
void* cInstancePtr;

Pointer to the C boxed value

getType
GType getType()

Get the GType of this boxed type.

gType
GType gType [@property getter]

Boxed GType property.

self
Boxed self()

Convenience method to return this cast to a type. For use in D with statements.

copy_
void* copy_()

Make a copy of the wrapped C boxed data.

boxedCopy
void* boxedCopy(void* cBoxed)

Copy a C boxed value using g_boxed_copy.

boxedFree
void boxedFree(void* cBoxed)

Free a C boxed value using g_boxed_free.