-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtalloc.h
84 lines (73 loc) · 2.45 KB
/
talloc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* Talloc is a replacement for the standard memory allocation routines that
* provides structure aware allocations.
*
* @author Dario Sneidermanis
*/
#ifndef __TALLOC_H__
#define __TALLOC_H__
#include <stddef.h>
/**
* Allocate a (contiguous) memory chunk.
*
* @param size amount of memory requested (in bytes).
* @param parent pointer to previously talloc'ed memory chunk from which this
* chunk depends, or NULL.
*
* @return pointer to the allocated memory chunk, or NULL if there was an error.
*/
void *talloc(size_t size, void *parent);
/**
* Allocate a zeroed (contiguous) memory chunk.
*
* @param size amount of memory requested (in bytes).
* @param parent pointer to previously talloc'ed memory chunk from which this
* chunk depends, or NULL.
*
* @return pointer to the allocated memory chunk, or NULL if there was an error.
*/
void *tzalloc(size_t size, void *parent);
/**
* Modify the size of a talloc'ed memory chunk.
*
* @param mem pointer to previously talloc'ed memory chunk.
* @param size amount of memory requested (in bytes).
*
* @return pointer to the allocated memory chunk, or NULL if there was an error.
*/
void *trealloc(void *mem, size_t size);
/**
* Deallocate a talloc'ed memory chunk and all the chunks depending on it.
*
* @param mem pointer to previously talloc'ed memory chunk.
*
* @return always NULL, can be safely ignored.
*/
void *tfree(void *mem);
/**
* Get the parent of a talloc'ed memory chunk (the chunk on which it depends).
*
* @param mem pointer to previously talloc'ed memory chunk.
*
* @return pointer to the parent memory chunk (could be NULL).
*/
void *talloc_get_parent(void *mem);
/**
* Change the parent of a talloc'ed memory chunk. This will affect the
* dependencies of the entire subtree rooted at the given chunk.
*
* @param mem pointer to previously talloc'ed memory chunk.
* @param parent pointer to previously talloc'ed memory chunk from which this
* chunk depends, or NULL.
*/
void talloc_set_parent(void *mem, void *parent);
/**
* Remove a talloc'ed memory chunk from the dependency tree, taking care of its
* children (they will depend on parent).
*
* @param mem pointer to previously talloc'ed memory chunk.
* @param parent pointer to previously talloc'ed memory chunk from which this
* chunk's children will depend, or NULL.
*/
void talloc_steal(void *mem, void *parent);
#endif /* __TALLOC_H__ */