VLC  4.0.0-dev

The object resource functions tie resource allocation to an instance of a module through a VLC object. More...

Collaboration diagram for Object resources:

Macros

#define vlc_obj_malloc(o, s)   vlc_obj_malloc(VLC_OBJECT(o), s)
 
#define vlc_obj_calloc(o, n, s)   vlc_obj_calloc(VLC_OBJECT(o), n, s)
 
#define vlc_obj_strdup(o, s)   vlc_obj_strdup(VLC_OBJECT(o), s)
 
#define vlc_obj_free(o, p)   vlc_obj_free(VLC_OBJECT(o), p)
 

Functions

VLC_MALLOC void * vlc_obj_malloc (_Generic((vlc_object_t *obj) ->obj, struct vlc_object_marker *:(vlc_object_t *obj), default:(&((vlc_object_t *obj) ->obj))), size_t size)
 Allocates memory for a module. More...
 
VLC_MALLOC void * vlc_obj_calloc (_Generic((vlc_object_t *obj) ->obj, struct vlc_object_marker *:(vlc_object_t *obj), default:(&((vlc_object_t *obj) ->obj))), size_t nmemb, size_t size)
 Allocates a zero-initialized table for a module. More...
 
VLC_MALLOC char * vlc_obj_strdup (_Generic((vlc_object_t *obj) ->obj, struct vlc_object_marker *:(vlc_object_t *obj), default:(&((vlc_object_t *obj) ->obj))), const char *str)
 Duplicates a string for a module. More...
 
void vlc_obj_free (_Generic((vlc_object_t *obj) ->obj, struct vlc_object_marker *:(vlc_object_t *obj), default:(&((vlc_object_t *obj) ->obj))), void *ptr)
 Manually frees module memory. More...
 

Detailed Description

The object resource functions tie resource allocation to an instance of a module through a VLC object.

Such resource will be automatically freed, in first in last out order, when the module instance associated with the VLC object is terminated.

Specifically, if the module instance activation/probe function fails, the resource will be freed immediately after the failure. If the activation succeeds, the resource will be freed when the module instance is terminated.

This is a convenience mechanism to save explicit clean-up function calls in modules.

Macro Definition Documentation

◆ vlc_obj_calloc

#define vlc_obj_calloc (   o,
  n,
 
)    vlc_obj_calloc(VLC_OBJECT(o), n, s)

◆ vlc_obj_free

#define vlc_obj_free (   o,
  p 
)    vlc_obj_free(VLC_OBJECT(o), p)

◆ vlc_obj_malloc

#define vlc_obj_malloc (   o,
 
)    vlc_obj_malloc(VLC_OBJECT(o), s)

◆ vlc_obj_strdup

#define vlc_obj_strdup (   o,
 
)    vlc_obj_strdup(VLC_OBJECT(o), s)

Function Documentation

◆ vlc_obj_calloc()

VLC_MALLOC void* vlc_obj_calloc ( _Generic((vlc_object_t *obj) ->obj, struct vlc_object_marker *:(vlc_object_t *obj), default:(&((vlc_object_t *obj) ->obj)))  ,
size_t  nmemb,
size_t  size 
)

Allocates a zero-initialized table for a module.

This function allocates a table from the heap for a module instance. The memory is initialized to all zeroes.

Parameters
objVLC object to tie the memory allocation to
nmembnumber of table entries
sizebyte size of a table entry
Returns
a pointer to the allocated memory, or NULL on error (errno is set).

◆ vlc_obj_free()

void vlc_obj_free ( _Generic((vlc_object_t *obj) ->obj, struct vlc_object_marker *:(vlc_object_t *obj), default:(&((vlc_object_t *obj) ->obj)))  ,
void *  ptr 
)

Manually frees module memory.

This function manually frees a resource allocated with vlc_obj_malloc(), vlc_obj_calloc() or vlc_obj_strdup() before the module instance is terminated. This is seldom necessary.

Parameters
objVLC object that the allocation was tied to
ptrpointer to the allocated resource

◆ vlc_obj_malloc()

VLC_MALLOC void* vlc_obj_malloc ( _Generic((vlc_object_t *obj) ->obj, struct vlc_object_marker *:(vlc_object_t *obj), default:(&((vlc_object_t *obj) ->obj)))  ,
size_t  size 
)

Allocates memory for a module.

This function allocates memory from the heap for a module instance. The memory is uninitialized.

Parameters
objVLC object to tie the memory allocation to
sizebyte size of the memory allocation
Returns
a pointer to the allocated memory, or NULL on error (errno is set).

◆ vlc_obj_strdup()

VLC_MALLOC char* vlc_obj_strdup ( _Generic((vlc_object_t *obj) ->obj, struct vlc_object_marker *:(vlc_object_t *obj), default:(&((vlc_object_t *obj) ->obj)))  ,
const char *  str 
)

Duplicates a string for a module.

This function allocates a copy of a nul-terminated string for a module instance.

Parameters
objVLC object to tie the memory allocation to
strstring to copy
Returns
a pointer to the copy, or NULL on error (errno is set).