Allocator

class Allocator(**properties: Any)

Superclasses: Object, InitiallyUnowned, Object

Memory is usually created by allocators with a alloc() method call. When None 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.

Methods

class Allocator
alloc(size: int, params: AllocationParams | None = None) Memory | None

Use allocator to allocate a new memory block with memory that is at least size big.

The optional params can specify the prefix and padding for the memory. If None is passed, no flags, no extra prefix/padding and a default alignment is used.

The prefix/padding will be filled with 0 if flags contains GST_MEMORY_FLAG_ZERO_PREFIXED and GST_MEMORY_FLAG_ZERO_PADDED respectively.

When allocator is None, the default allocator will be used.

The alignment in params is given as a bitmask so that align + 1 equals the amount of bytes to align to. For example, to align to 8 bytes, use an alignment of 7.

Parameters:
  • size – size of the visible memory area

  • params – optional parameters

find(name: str | None = None) Allocator | None

Find a previously registered allocator with name. When name is None, the default allocator will be returned.

Parameters:

name – the name of the allocator

free(memory: Memory) None

Free memory that was previously allocated with alloc().

Parameters:

memory – the memory to free

register(name: str, allocator: Allocator) None

Registers the memory allocator with name.

Parameters:
  • name – the name of the allocator

  • allocatorAllocator

set_default() None

Set the default allocator.

Virtual Methods

class Allocator
do_alloc(size: int, params: AllocationParams | None = None) Memory | None

Use allocator to allocate a new memory block with memory that is at least size big.

The optional params can specify the prefix and padding for the memory. If None is passed, no flags, no extra prefix/padding and a default alignment is used.

The prefix/padding will be filled with 0 if flags contains GST_MEMORY_FLAG_ZERO_PREFIXED and GST_MEMORY_FLAG_ZERO_PADDED respectively.

When allocator is None, the default allocator will be used.

The alignment in params is given as a bitmask so that align + 1 equals the amount of bytes to align to. For example, to align to 8 bytes, use an alignment of 7.

Parameters:
  • size – size of the visible memory area

  • params – optional parameters

do_free(memory: Memory) None

Free memory that was previously allocated with alloc().

Parameters:

memory – the memory to free

Fields

class Allocator
mem_copy

The implementation of the GstMemoryCopyFunction

mem_is_span

The implementation of the GstMemoryIsSpanFunction

mem_map

The implementation of the GstMemoryMapFunction

mem_map_full

The implementation of the GstMemoryMapFullFunction. Will be used instead of mem_map if present. (Since: 1.6)

mem_share

The implementation of the GstMemoryShareFunction

mem_type
mem_unmap

The implementation of the GstMemoryUnmapFunction

mem_unmap_full

The implementation of the GstMemoryUnmapFullFunction. Will be used instead of mem_unmap if present. (Since: 1.6)

object
priv