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_alloc() method call. When NULL is used as the allocator, the default allocator will be used.

New allocators can be registered with gst_allocator_register(). Allocators are identified by name and can be retrieved with gst_allocator_find(). gst_allocator_set_default() can be used to change the default allocator.

New memory can be created with gst_memory_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 gst_memory_get_sizes() and gst_memory_resize() respectively.

Getting access to the data of the memory is performed with gst_memory_map(). The call will return a pointer to offset bytes into the region of memory. After the memory access is completed, gst_memory_unmap() should be called.

Memory can be copied with gst_memory_copy(), which will return a writable copy. gst_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_is_span() returns TRUE.

Last reviewed on 2012-03-28 (0.11.3)

Constructors

this
this(GstMemory* gstMemory)

Sets our main struct and passes it to the parent class

Members

Functions

copy
Memory copy(gssize offset, gssize 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 all bytes from offset.

doref
Memory doref()

Increase the refcount of this memory.

getMemoryStruct
GstMemory* getMemoryStruct()
Undocumented in source. Be warned that the author may not have intended to support it.
getSizes
gsize getSizes(gsize offset, gsize maxsize)

Get the current size, offset and maxsize of mem.

getStruct
void* getStruct()

the main Gtk struct as a void*

init
void init(GstMemoryFlags flags, Allocator allocator, Memory parent, gsize maxsize, gsize alig, gsize offset, gsize size)

Initializes a newly allocated mem with the given parameters. This function will call gst_mini_object_init() with the default memory parameters.

isSpan
int isSpan(Memory mem2, gsize offset)

Check if mem1 and mem2 share the memory with a common parent memory object and that the memory is contiguous. If this is the case, the memory of mem1 and mem2 can be merged efficiently by performing gst_memory_share() on the parent object from the returned offset.

isType
int isType(string memType)

Check if mem if allocated with an allocator for mem_type. Since 1.2

makeMapped
Memory makeMapped(GstMapInfo info, GstMapFlags 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. This function takes ownership of old mem and returns a reference to a new GstMemory.

map
int map(GstMapInfo info, GstMapFlags flags)

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

resize
void resize(gssize offset, gsize size)

Resize the memory region. mem should be writable and offset + size should be less than the maxsize of mem. GST_MEMORY_FLAG_ZERO_PREFIXED and GST_MEMORY_FLAG_ZERO_PADDED will be cleared when offset or padding is increased respectively.

share
Memory share(gssize offset, gssize 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 not-writable. size can be set to -1 to return a share all bytes from offset.

unmap
void unmap(GstMapInfo info)

Release the memory obtained with gst_memory_map()

unref
void unref()

Decrease the refcount of an memory, freeing it if the refcount reaches 0.

Variables

gstMemory
GstMemory* gstMemory;

the main Gtk struct

Meta