table of contents
The talloc reference function.(3) | talloc | The talloc reference function.(3) |
NAME¶
The talloc reference function. -
This module contains the definitions around talloc references.
Modules¶
The talloc array functions
Talloc contains some handy helpers for handling Arrays conveniently.
Functions¶
int talloc_increase_ref_count (const void *ptr)
Increase the reference count of a talloc chunk. size_t
talloc_reference_count (const void *ptr)
Get the number of references to a talloc chunk. void *
talloc_reference (const void *ctx, const void *ptr)
Create an additional talloc parent to a pointer. int
talloc_unlink (const void *context, void *ptr)
Remove a specific parent from a talloc chunk. void *
talloc_autofree_context (void) _DEPRECATED_
Provide a talloc context that is freed at program exit. size_t
talloc_get_size (const void *ctx)
Get the size of a talloc chunk. void talloc_show_parents (const
void *context, FILE *file)
Show the parentage of a context. int talloc_is_parent (const
void *context, const void *ptr)
Check if a context is parent of a talloc chunk. void *
talloc_reparent (const void *old_parent, const void *new_parent,
const void *ptr)
Change the parent context of a talloc pointer.
Detailed Description¶
This module contains the definitions around talloc references.
Function Documentation¶
void* talloc_autofree_context (void)¶
Provide a talloc context that is freed at program exit. This is a handy utility function that returns a talloc context which will be automatically freed on program exit. This can be used to reduce the noise in memory leak reports.
Never use this in code that might be used in objects loaded with dlopen and unloaded with dlclose. talloc_autofree_context() internally uses atexit(3). Some platforms like modern Linux handles this fine, but for example FreeBSD does not deal well with dlopen() and atexit() used simultaneously: dlclose() does not clean up the list of atexit-handlers, so when the program exits the code that was registered from within talloc_autofree_context() is gone, the program crashes at exit.
Returns:
size_t talloc_get_size (const void *ctx)¶
Get the size of a talloc chunk. This function lets you know the amount of memory allocated so far by this context. It does NOT account for subcontext memory. This can be used to calculate the size of an array.
Parameters:
Returns:
int talloc_increase_ref_count (const void *ptr)¶
Increase the reference count of a talloc chunk. The talloc_increase_ref_count(ptr) function is exactly equivalent to:
talloc_reference(NULL, ptr);
You can use either syntax, depending on which you think is clearer in your code.
Parameters:
Returns:
int talloc_is_parent (const void *context, const void *ptr)¶
Check if a context is parent of a talloc chunk. This checks if context is referenced in the talloc hierarchy above ptr.
Parameters:
ptr The talloc chunk to check.
Returns:
void* talloc_reference (const void *ctx, const void *ptr)¶
Create an additional talloc parent to a pointer. The talloc_reference() function makes 'context' an additional parent of ptr. Each additional reference consumes around 48 bytes of memory on intel x86 platforms.
If ptr is NULL, then the function is a no-op, and simply returns NULL.
After creating a reference you can free it in one of the following ways:
- you can talloc_free() any parent of the original pointer. That will reduce the number of parents of this pointer by 1, and will cause this pointer to be freed if it runs out of parents.
- you can talloc_free() the pointer itself if it has at maximum one parent. This behaviour has been changed since the release of version 2.0. Further informations in the description of 'talloc_free'.
For more control on which parent to remove, see talloc_unlink()
Parameters:
ptr The pointer you want to create an additional parent for.
Returns:
Warning:
Example:
unsigned int *a, *b, *c; a = talloc(NULL, unsigned int); b = talloc(NULL, unsigned int); c = talloc(a, unsigned int); // b also serves as a parent of c. talloc_reference(b, c);
See Also:
size_t talloc_reference_count (const void *ptr)¶
Get the number of references to a talloc chunk.
Parameters:
Returns:
void* talloc_reparent (const void *old_parent, const void *new_parent, const void *ptr)¶
Change the parent context of a talloc pointer. The function changes the parent context of a talloc pointer. It is typically used when the context that the pointer is currently a child of is going to be freed and you wish to keep the memory for a longer time.
The difference between talloc_reparent() and talloc_steal() is that talloc_reparent() can specify which parent you wish to change. This is useful when a pointer has multiple parents via references.
Parameters:
new_parent
ptr
Returns:
void talloc_show_parents (const void *context, FILE *file)¶
Show the parentage of a context.
Parameters:
file The output to use, a file, stdout or stderr.
int talloc_unlink (const void *context, void *ptr)¶
Remove a specific parent from a talloc chunk. The function removes a specific parent from ptr. The context passed must either be a context used in talloc_reference() with this pointer, or must be a direct parent of ptr.
You can just use talloc_free() instead of talloc_unlink() if there is at maximum one parent. This behaviour has been changed since the release of version 2.0. Further informations in the description of 'talloc_free'.
Parameters:
ptr The talloc ptr you want to remove the parent from.
Returns:
Note:
Warning:
Example:
unsigned int *a, *b, *c; a = talloc(NULL, unsigned int); b = talloc(NULL, unsigned int); c = talloc(a, unsigned int); // b also serves as a parent of c. talloc_reference(b, c); talloc_unlink(b, c);
Author¶
Generated automatically by Doxygen for talloc from the source code.
Wed Apr 1 2020 | Version 2.0 |