Fri, 24 Jan 2025 21:12:09 +0100
assign proper names to the documentation topics
relates to #451
1143
0559812df10c
assign proper names to the documentation topics
Mike Becker <universe@uap-core.de>
parents:
1142
diff
changeset
|
1 | # Allocator |
1141 | 2 | |
3 | The UCX allocator provides an interface for implementing an own memory allocation mechanism. | |
4 | Various function in UCX provide an additional alternative signature that takes an allocator as | |
5 | argument. A default allocator implementation using the stdlib memory management functions is | |
6 | available via the global symbol `cxDefaultAllocator`. | |
7 | ||
8 | If you want to define your own allocator, you need to initialize the `CxAllocator` structure | |
9 | with a pointer to an allocator class (containing function pointers for the memory management | |
10 | functions) and an optional pointer to an arbitrary memory region that can be used to store | |
11 | state information for the allocator. An example is shown below: | |
12 | ||
13 | ```c | |
14 | struct my_allocator_state { | |
15 | size_t total; | |
16 | size_t avail; | |
17 | char mem[]; | |
18 | }; | |
19 | ||
20 | static cx_allocator_class my_allocator_class = { | |
21 | my_malloc_impl, | |
22 | my_realloc_impl, // all these functions are somewhere defined | |
23 | my_calloc_impl, | |
24 | my_free_impl | |
25 | }; | |
26 | ||
27 | CxAllocator create_my_allocator(size_t n) { | |
28 | CxAllocator alloc; | |
29 | alloc.cl = &my_allocator_class; | |
30 | alloc.data = calloc(1, sizeof(struct my_allocator_state) + n); | |
31 | return alloc; | |
32 | } | |
33 | ``` | |
34 | ||
1142
9437530176bc
add symbols that need documentation as TODOs
Mike Becker <universe@uap-core.de>
parents:
1141
diff
changeset
|
35 | ## Undocumented Symbols (TODO) |
9437530176bc
add symbols that need documentation as TODOs
Mike Becker <universe@uap-core.de>
parents:
1141
diff
changeset
|
36 | |
9437530176bc
add symbols that need documentation as TODOs
Mike Becker <universe@uap-core.de>
parents:
1141
diff
changeset
|
37 | ### cxCalloc |
9437530176bc
add symbols that need documentation as TODOs
Mike Becker <universe@uap-core.de>
parents:
1141
diff
changeset
|
38 | ### cx_default_allocator |
9437530176bc
add symbols that need documentation as TODOs
Mike Becker <universe@uap-core.de>
parents:
1141
diff
changeset
|
39 | ### cxDefaultAllocator |
9437530176bc
add symbols that need documentation as TODOs
Mike Becker <universe@uap-core.de>
parents:
1141
diff
changeset
|
40 | ### cxFree |
9437530176bc
add symbols that need documentation as TODOs
Mike Becker <universe@uap-core.de>
parents:
1141
diff
changeset
|
41 | ### cxMalloc |
9437530176bc
add symbols that need documentation as TODOs
Mike Becker <universe@uap-core.de>
parents:
1141
diff
changeset
|
42 | ### cxRealloc |
9437530176bc
add symbols that need documentation as TODOs
Mike Becker <universe@uap-core.de>
parents:
1141
diff
changeset
|
43 | ### cxReallocArray |
9437530176bc
add symbols that need documentation as TODOs
Mike Becker <universe@uap-core.de>
parents:
1141
diff
changeset
|
44 | ### cx_reallocate_ |
9437530176bc
add symbols that need documentation as TODOs
Mike Becker <universe@uap-core.de>
parents:
1141
diff
changeset
|
45 | ### cxReallocate_ |
9437530176bc
add symbols that need documentation as TODOs
Mike Becker <universe@uap-core.de>
parents:
1141
diff
changeset
|
46 | ### cx_reallocatearray_ |
9437530176bc
add symbols that need documentation as TODOs
Mike Becker <universe@uap-core.de>
parents:
1141
diff
changeset
|
47 | ### cxReallocateArray_ |