src/cx/allocator.h

Sun, 28 Dec 2025 17:31:20 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 28 Dec 2025 17:31:20 +0100
changeset 1675
36c0fb2b60b2
parent 1610
ce0b0bf7d29c
permissions
-rw-r--r--

overhaul all attributes

391
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 *
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 *
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 *
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 *
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 *
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 */
431
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
28 /**
1085
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
29 * @file allocator.h
431
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
30 * Interface for custom allocators.
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
31 */
391
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
32
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
33 #ifndef UCX_ALLOCATOR_H
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34 #define UCX_ALLOCATOR_H
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
35
484
9e6900b1cf9d add common.h include to all other header files
Mike Becker <universe@uap-core.de>
parents: 465
diff changeset
36 #include "common.h"
391
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37
431
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
38 /**
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
39 * The class definition for an allocator.
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
40 */
396
3539dd99ab92 make cx_allocator_class shared
Mike Becker <universe@uap-core.de>
parents: 394
diff changeset
41 typedef struct {
431
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
42 /**
465
1e3cb39815f8 remove redundant documentation for function pointers
Mike Becker <universe@uap-core.de>
parents: 461
diff changeset
43 * The allocator's malloc() implementation.
431
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
44 */
1426
3a89b31f0724 clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents: 1424
diff changeset
45 void *(*malloc)(void *data, size_t n);
431
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
46
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
47 /**
465
1e3cb39815f8 remove redundant documentation for function pointers
Mike Becker <universe@uap-core.de>
parents: 461
diff changeset
48 * The allocator's realloc() implementation.
431
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
49 */
1426
3a89b31f0724 clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents: 1424
diff changeset
50 void *(*realloc)(void *data, void *mem, size_t n);
431
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
51
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
52 /**
465
1e3cb39815f8 remove redundant documentation for function pointers
Mike Becker <universe@uap-core.de>
parents: 461
diff changeset
53 * The allocator's calloc() implementation.
431
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
54 */
1426
3a89b31f0724 clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents: 1424
diff changeset
55 void *(*calloc)(void *data, size_t nmemb, size_t size);
431
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
56
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
57 /**
465
1e3cb39815f8 remove redundant documentation for function pointers
Mike Becker <universe@uap-core.de>
parents: 461
diff changeset
58 * The allocator's free() implementation.
431
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
59 */
1426
3a89b31f0724 clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents: 1424
diff changeset
60 void (*free)(void *data, void *mem);
396
3539dd99ab92 make cx_allocator_class shared
Mike Becker <universe@uap-core.de>
parents: 394
diff changeset
61 } cx_allocator_class;
3539dd99ab92 make cx_allocator_class shared
Mike Becker <universe@uap-core.de>
parents: 394
diff changeset
62
431
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
63 /**
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
64 * Structure holding the data for an allocator.
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
65 */
394
80c31ebd66c1 high level allocator functions should be real functions, not macros
Mike Becker <universe@uap-core.de>
parents: 393
diff changeset
66 struct cx_allocator_s {
431
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
67 /**
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
68 * A pointer to the instance of the allocator class.
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
69 */
396
3539dd99ab92 make cx_allocator_class shared
Mike Becker <universe@uap-core.de>
parents: 394
diff changeset
70 cx_allocator_class *cl;
431
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
71 /**
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
72 * A pointer to the data this allocator uses.
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
73 */
397
cfc1193b1e65 removes unnecessary cx_allocator typedef
Mike Becker <universe@uap-core.de>
parents: 396
diff changeset
74 void *data;
391
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
75 };
431
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
76
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
77 /**
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
78 * High-Level type alias for the allocator type.
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
79 */
500
eb9e7bd40a8e do not hide pointers behind typedefs
Mike Becker <universe@uap-core.de>
parents: 484
diff changeset
80 typedef struct cx_allocator_s CxAllocator;
391
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
81
431
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
82 /**
1318
12fa1d37fe48 allow changing the cxDefaultAllocator - resolves #669
Mike Becker <universe@uap-core.de>
parents: 1188
diff changeset
83 * A pre-defined allocator using standard library malloc() etc.
431
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
84 */
1426
3a89b31f0724 clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents: 1424
diff changeset
85 CX_EXPORT extern const CxAllocator * const cxStdlibAllocator;
1318
12fa1d37fe48 allow changing the cxDefaultAllocator - resolves #669
Mike Becker <universe@uap-core.de>
parents: 1188
diff changeset
86
12fa1d37fe48 allow changing the cxDefaultAllocator - resolves #669
Mike Becker <universe@uap-core.de>
parents: 1188
diff changeset
87 /**
12fa1d37fe48 allow changing the cxDefaultAllocator - resolves #669
Mike Becker <universe@uap-core.de>
parents: 1188
diff changeset
88 * The default allocator that is used by UCX.
12fa1d37fe48 allow changing the cxDefaultAllocator - resolves #669
Mike Becker <universe@uap-core.de>
parents: 1188
diff changeset
89 * Initialized with cxStdlibAllocator, but you may change it.
12fa1d37fe48 allow changing the cxDefaultAllocator - resolves #669
Mike Becker <universe@uap-core.de>
parents: 1188
diff changeset
90 */
1426
3a89b31f0724 clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents: 1424
diff changeset
91 CX_EXPORT extern const CxAllocator * cxDefaultAllocator;
391
f094a53c1178 adds allocator interface and default implementation
Mike Becker <universe@uap-core.de>
parents:
diff changeset
92
431
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
93 /**
503
a89857072ace add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
94 * Function pointer type for destructor functions.
a89857072ace add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
95 *
a89857072ace add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
96 * A destructor function deallocates possible contents and MAY free the memory
1085
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
97 * pointed to by @p memory. Read the documentation of the respective function
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 963
diff changeset
98 * pointer to learn if a destructor SHALL, MAY, or MUST NOT free the memory in
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 963
diff changeset
99 * that particular implementation.
503
a89857072ace add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
100 *
a89857072ace add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
101 * @param memory a pointer to the object to destruct
a89857072ace add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
102 */
891
49d8cff6f0ee make all function attributes leading - fixes #425
Mike Becker <universe@uap-core.de>
parents: 890
diff changeset
103 typedef void (*cx_destructor_func)(void *memory);
503
a89857072ace add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
104
a89857072ace add new destructor API and apply it to CxList
Mike Becker <universe@uap-core.de>
parents: 500
diff changeset
105 /**
528
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
106 * Function pointer type for destructor functions.
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
107 *
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
108 * A destructor function deallocates possible contents and MAY free the memory
1085
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
109 * pointed to by @p memory. Read the documentation of the respective function
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 963
diff changeset
110 * pointer to learn if a destructor SHALL, MAY, or MUST NOT free the memory in
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 963
diff changeset
111 * that particular implementation.
528
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
112 *
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
113 * @param data an optional pointer to custom data
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
114 * @param memory a pointer to the object to destruct
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
115 */
1426
3a89b31f0724 clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents: 1424
diff changeset
116 typedef void (*cx_destructor_func2)(void *data, void *memory);
528
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
117
1431
1ec36e652e57 define the function pointer for clone functions
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
118
1ec36e652e57 define the function pointer for clone functions
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
119 /**
1ec36e652e57 define the function pointer for clone functions
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
120 * Function pointer type for clone functions.
1ec36e652e57 define the function pointer for clone functions
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
121 *
1ec36e652e57 define the function pointer for clone functions
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
122 * A clone function is supposed to create a deep copy of the memory pointed to
1ec36e652e57 define the function pointer for clone functions
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
123 * by the @p source pointer.
1ec36e652e57 define the function pointer for clone functions
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
124 * If the @p target pointer is non-null, the clone function is supposed to store
1ec36e652e57 define the function pointer for clone functions
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
125 * the copy into that memory region.
1ec36e652e57 define the function pointer for clone functions
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
126 * Otherwise, the clone function shall use the specified @p allocator to create
1ec36e652e57 define the function pointer for clone functions
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
127 * a new object.
1ec36e652e57 define the function pointer for clone functions
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
128 *
1ec36e652e57 define the function pointer for clone functions
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
129 * The return value of a clone function is always a pointer to the target
1ec36e652e57 define the function pointer for clone functions
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
130 * memory region, or @c NULL if any allocation failed.
1ec36e652e57 define the function pointer for clone functions
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
131 * A clone function SHOULD NOT fail for any other reason than an allocation
1ec36e652e57 define the function pointer for clone functions
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
132 * failure.
1ec36e652e57 define the function pointer for clone functions
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
133 *
1ec36e652e57 define the function pointer for clone functions
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
134 * @param target the target memory or @c NULL, if memory shall be allocated
1ec36e652e57 define the function pointer for clone functions
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
135 * @param source the source memory
1ec36e652e57 define the function pointer for clone functions
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
136 * @param allocator the allocator that shall be used
1ec36e652e57 define the function pointer for clone functions
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
137 * @param data optional additional data
1ec36e652e57 define the function pointer for clone functions
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
138 * @return either the specified @p target, a pointer to the allocated memory,
1ec36e652e57 define the function pointer for clone functions
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
139 * or @c NULL, if any error occurred
1ec36e652e57 define the function pointer for clone functions
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
140 */
1593
0df5128ab675 fix incorrect definition of cx_clone_func fptr
Mike Becker <universe@uap-core.de>
parents: 1554
diff changeset
141 typedef void*(*cx_clone_func)(void *target, const void *source,
1431
1ec36e652e57 define the function pointer for clone functions
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
142 const CxAllocator *allocator, void *data);
1ec36e652e57 define the function pointer for clone functions
Mike Becker <universe@uap-core.de>
parents: 1426
diff changeset
143
528
4fbfac557df8 #179 improve API for list content destruction
Mike Becker <universe@uap-core.de>
parents: 526
diff changeset
144 /**
1539
2cbdb482d325 add cx_system_page_size() to allocator.h
Mike Becker <universe@uap-core.de>
parents: 1431
diff changeset
145 * Returns the system's memory page size.
2cbdb482d325 add cx_system_page_size() to allocator.h
Mike Becker <universe@uap-core.de>
parents: 1431
diff changeset
146 *
2cbdb482d325 add cx_system_page_size() to allocator.h
Mike Becker <universe@uap-core.de>
parents: 1431
diff changeset
147 * If the page size cannot be retrieved from the system,
2cbdb482d325 add cx_system_page_size() to allocator.h
Mike Becker <universe@uap-core.de>
parents: 1431
diff changeset
148 * a default of 4096 bytes is assumed.
2cbdb482d325 add cx_system_page_size() to allocator.h
Mike Becker <universe@uap-core.de>
parents: 1431
diff changeset
149 *
2cbdb482d325 add cx_system_page_size() to allocator.h
Mike Becker <universe@uap-core.de>
parents: 1431
diff changeset
150 * @return the system's memory page size in bytes
2cbdb482d325 add cx_system_page_size() to allocator.h
Mike Becker <universe@uap-core.de>
parents: 1431
diff changeset
151 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1610
diff changeset
152 CX_EXTERN CX_NODISCARD
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1610
diff changeset
153 unsigned long cx_system_page_size(void);
1539
2cbdb482d325 add cx_system_page_size() to allocator.h
Mike Becker <universe@uap-core.de>
parents: 1431
diff changeset
154
2cbdb482d325 add cx_system_page_size() to allocator.h
Mike Becker <universe@uap-core.de>
parents: 1431
diff changeset
155 /**
1610
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
156 * Reallocate a previously allocated block.
726
44986c0e2b05 add a low-level stdlib-based cx_reallocate()
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
157 *
1610
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
158 * Internal function - do not use.
726
44986c0e2b05 add a low-level stdlib-based cx_reallocate()
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
159 *
44986c0e2b05 add a low-level stdlib-based cx_reallocate()
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
160 * @param mem pointer to the pointer to allocated block
44986c0e2b05 add a low-level stdlib-based cx_reallocate()
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
161 * @param n the new size in bytes
1085
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
162 * @retval zero success
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
163 * @retval non-zero failure
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
164 * @see cx_reallocatearray()
726
44986c0e2b05 add a low-level stdlib-based cx_reallocate()
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
165 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1610
diff changeset
166 CX_EXTERN CX_NONNULL CX_NODISCARD
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1610
diff changeset
167 int cx_reallocate_(void **mem, size_t n);
726
44986c0e2b05 add a low-level stdlib-based cx_reallocate()
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
168
44986c0e2b05 add a low-level stdlib-based cx_reallocate()
Mike Becker <universe@uap-core.de>
parents: 677
diff changeset
169 /**
1610
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
170 * Reallocate a previously allocated block.
963
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
171 *
1610
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
172 * Internal function - do not use.
963
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
173 *
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
174 * @param mem pointer to the pointer to allocated block
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
175 * @param nmemb the number of elements
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
176 * @param size the size of each element
1085
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
177 * @retval zero success
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
178 * @retval non-zero failure
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
179 * @see cx_reallocate()
963
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
180 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1610
diff changeset
181 CX_EXTERN CX_NONNULL CX_NODISCARD
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1610
diff changeset
182 int cx_reallocatearray_(void **mem, size_t nmemb, size_t size);
963
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
183
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
184 /**
1185
d825aca193d3 use reallocate instead of re-allocate
Mike Becker <universe@uap-core.de>
parents: 1180
diff changeset
185 * Reallocate a previously allocated block and changes the pointer in-place,
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 963
diff changeset
186 * if necessary.
963
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
187 *
1318
12fa1d37fe48 allow changing the cxDefaultAllocator - resolves #669
Mike Becker <universe@uap-core.de>
parents: 1188
diff changeset
188 * @note This will use stdlib reallocate and @em not the cxDefaultAllocator.
12fa1d37fe48 allow changing the cxDefaultAllocator - resolves #669
Mike Becker <universe@uap-core.de>
parents: 1188
diff changeset
189 *
1085
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
190 * @par Error handling
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
191 * @c errno will be set by realloc() on failure.
935
312fb24c14de add convenience macro for cx_reallocate to hide the (void**) cast
Mike Becker <universe@uap-core.de>
parents: 891
diff changeset
192 *
1085
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
193 * @param mem (@c void**) pointer to the pointer to allocated block
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
194 * @param n (@c size_t) the new size in bytes
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
195 * @retval zero success
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
196 * @retval non-zero failure
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
197 * @see cx_reallocatearray()
935
312fb24c14de add convenience macro for cx_reallocate to hide the (void**) cast
Mike Becker <universe@uap-core.de>
parents: 891
diff changeset
198 */
1134
60edcd57d54c fix that some IDEs cannot resolve documentation
Mike Becker <universe@uap-core.de>
parents: 1087
diff changeset
199 #define cx_reallocate(mem, n) cx_reallocate_((void**)(mem), n)
935
312fb24c14de add convenience macro for cx_reallocate to hide the (void**) cast
Mike Becker <universe@uap-core.de>
parents: 891
diff changeset
200
312fb24c14de add convenience macro for cx_reallocate to hide the (void**) cast
Mike Becker <universe@uap-core.de>
parents: 891
diff changeset
201 /**
1185
d825aca193d3 use reallocate instead of re-allocate
Mike Becker <universe@uap-core.de>
parents: 1180
diff changeset
202 * Reallocate a previously allocated block and changes the pointer in-place,
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 963
diff changeset
203 * if necessary.
963
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
204 *
1085
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
205 * The size is calculated by multiplying @p nemb and @p size.
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
206 *
1318
12fa1d37fe48 allow changing the cxDefaultAllocator - resolves #669
Mike Becker <universe@uap-core.de>
parents: 1188
diff changeset
207 * @note This will use stdlib reallocate and @em not the cxDefaultAllocator.
12fa1d37fe48 allow changing the cxDefaultAllocator - resolves #669
Mike Becker <universe@uap-core.de>
parents: 1188
diff changeset
208 *
1085
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
209 * @par Error handling
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
210 * @c errno will be set by realloc() on failure or when the multiplication of
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
211 * @p nmemb and @p size overflows.
963
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
212 *
1085
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
213 * @param mem (@c void**) pointer to the pointer to allocated block
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
214 * @param nmemb (@c size_t) the number of elements
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
215 * @param size (@c size_t) the size of each element
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
216 * @retval zero success
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
217 * @retval non-zero failure
963
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
218 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 963
diff changeset
219 #define cx_reallocatearray(mem, nmemb, size) \
1134
60edcd57d54c fix that some IDEs cannot resolve documentation
Mike Becker <universe@uap-core.de>
parents: 1087
diff changeset
220 cx_reallocatearray_((void**)(mem), nmemb, size)
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 963
diff changeset
221
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 963
diff changeset
222 /**
1332
dd5d2402d161 implement zalloc() - resolves #679
Mike Becker <universe@uap-core.de>
parents: 1319
diff changeset
223 * Allocates memory and sets every byte to zero.
dd5d2402d161 implement zalloc() - resolves #679
Mike Becker <universe@uap-core.de>
parents: 1319
diff changeset
224 *
dd5d2402d161 implement zalloc() - resolves #679
Mike Becker <universe@uap-core.de>
parents: 1319
diff changeset
225 * @param n (@c size_t) the number of bytes
dd5d2402d161 implement zalloc() - resolves #679
Mike Becker <universe@uap-core.de>
parents: 1319
diff changeset
226 * @return (@c void*) a pointer to the allocated memory
dd5d2402d161 implement zalloc() - resolves #679
Mike Becker <universe@uap-core.de>
parents: 1319
diff changeset
227 */
dd5d2402d161 implement zalloc() - resolves #679
Mike Becker <universe@uap-core.de>
parents: 1319
diff changeset
228 #define cx_zalloc(n) calloc(1, n)
dd5d2402d161 implement zalloc() - resolves #679
Mike Becker <universe@uap-core.de>
parents: 1319
diff changeset
229
dd5d2402d161 implement zalloc() - resolves #679
Mike Becker <universe@uap-core.de>
parents: 1319
diff changeset
230 /**
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 963
diff changeset
231 * Free a block allocated by this allocator.
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 963
diff changeset
232 *
1085
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
233 * @note Freeing a block of a different allocator is undefined.
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 963
diff changeset
234 *
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 963
diff changeset
235 * @param allocator the allocator
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 963
diff changeset
236 * @param mem a pointer to the block to free
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 963
diff changeset
237 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1610
diff changeset
238 CX_EXTERN CX_NONNULL_ARG(1)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1610
diff changeset
239 void cxFree(const CxAllocator *allocator, void *mem);
963
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
240
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
241 /**
1085
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
242 * Allocate @p n bytes of memory.
431
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
243 *
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
244 * @param allocator the allocator
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
245 * @param n the number of bytes
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
246 * @return a pointer to the allocated memory
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
247 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1610
diff changeset
248 CX_EXTERN CX_NODISCARD CX_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1610
diff changeset
249 CX_MALLOC CX_DEALLOC_UCX CX_ALLOCSIZE(2)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1610
diff changeset
250 void *cxMalloc(const CxAllocator *allocator, size_t n);
397
cfc1193b1e65 removes unnecessary cx_allocator typedef
Mike Becker <universe@uap-core.de>
parents: 396
diff changeset
251
431
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
252 /**
1185
d825aca193d3 use reallocate instead of re-allocate
Mike Becker <universe@uap-core.de>
parents: 1180
diff changeset
253 * Reallocate the previously allocated block in @p mem, making the new block
1085
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
254 * @p n bytes long.
1424
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1332
diff changeset
255 * This function may return the same pointer passed to it if moving
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 963
diff changeset
256 * the memory was not necessary.
431
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
257 *
1085
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
258 * @note Re-allocating a block allocated by a different allocator is undefined.
431
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
259 *
1610
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
260 * @attention This function is bug-prone. Consider using cxReallocate().
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
261 *
431
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
262 * @param allocator the allocator
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
263 * @param mem pointer to the previously allocated block
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
264 * @param n the new size in bytes
1185
d825aca193d3 use reallocate instead of re-allocate
Mike Becker <universe@uap-core.de>
parents: 1180
diff changeset
265 * @return a pointer to the reallocated memory
431
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
266 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1610
diff changeset
267 CX_EXTERN CX_NODISCARD CX_NONNULL_ARG(1)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1610
diff changeset
268 CX_DEALLOC_UCX CX_ALLOCSIZE(3)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1610
diff changeset
269 void *cxRealloc(const CxAllocator *allocator, void *mem, size_t n);
397
cfc1193b1e65 removes unnecessary cx_allocator typedef
Mike Becker <universe@uap-core.de>
parents: 396
diff changeset
270
431
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
271 /**
1610
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
272 * Reallocate the previously allocated block in @p mem.
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
273 *
1424
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1332
diff changeset
274 * This function may return the same pointer passed to it if moving
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 963
diff changeset
275 * the memory was not necessary.
963
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
276 *
1085
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
277 * The size is calculated by multiplying @p nemb and @p size.
1424
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1332
diff changeset
278 * If that multiplication overflows, this function returns @c NULL, and @c errno
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 963
diff changeset
279 * will be set.
963
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
280 *
1085
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
281 * @note Re-allocating a block allocated by a different allocator is undefined.
963
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
282 *
1610
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
283 * @attention This function is bug-prone. Consider using cxReallocateArray().
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
284 *
963
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
285 * @param allocator the allocator
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
286 * @param mem pointer to the previously allocated block
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
287 * @param nmemb the number of elements
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
288 * @param size the size of each element
1185
d825aca193d3 use reallocate instead of re-allocate
Mike Becker <universe@uap-core.de>
parents: 1180
diff changeset
289 * @return a pointer to the reallocated memory
963
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
290 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1610
diff changeset
291 CX_EXTERN CX_NODISCARD CX_NONNULL_ARG(1)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1610
diff changeset
292 CX_DEALLOC_UCX CX_ALLOCSIZE(3, 4)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1610
diff changeset
293 void *cxReallocArray(const CxAllocator *allocator,
1426
3a89b31f0724 clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents: 1424
diff changeset
294 void *mem, size_t nmemb, size_t size);
963
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
295
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
296 /**
1610
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
297 * Reallocate a previously allocated block.
431
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
298 *
1610
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
299 * Internal function - do not use.
431
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
300 *
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
301 * @param allocator the allocator
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
302 * @param mem pointer to the pointer to allocated block
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
303 * @param n the new size in bytes
1085
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
304 * @retval zero success
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
305 * @retval non-zero failure
431
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
306 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1610
diff changeset
307 CX_EXTERN CX_NODISCARD CX_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1610
diff changeset
308 int cxReallocate_(const CxAllocator *allocator, void **mem, size_t n);
414
81a4c3a63e65 adds cxReallocate()
Mike Becker <universe@uap-core.de>
parents: 405
diff changeset
309
431
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
310 /**
1185
d825aca193d3 use reallocate instead of re-allocate
Mike Becker <universe@uap-core.de>
parents: 1180
diff changeset
311 * Reallocate a previously allocated block and changes the pointer in-place,
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 963
diff changeset
312 * if necessary.
1085
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
313 * This function acts like cxRealloc() using the pointer pointed to by @p mem.
963
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
314 *
1085
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
315 * @note Re-allocating a block allocated by a different allocator is undefined.
963
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
316 *
1085
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
317 * @par Error handling
1424
563033aa998c fixes tons of typos and grammar issues across the documentation - fixes #667
Mike Becker <universe@uap-core.de>
parents: 1332
diff changeset
318 * @c errno will be set if the underlying realloc function does so.
963
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
319 *
1087
128324af5164 don't document constness of arguments in macros
Mike Becker <universe@uap-core.de>
parents: 1085
diff changeset
320 * @param allocator (@c CxAllocator*) the allocator
1085
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
321 * @param mem (@c void**) pointer to the pointer to allocated block
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
322 * @param n (@c size_t) the new size in bytes
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
323 * @retval zero success
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
324 * @retval non-zero failure
963
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
325 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 963
diff changeset
326 #define cxReallocate(allocator, mem, n) \
1134
60edcd57d54c fix that some IDEs cannot resolve documentation
Mike Becker <universe@uap-core.de>
parents: 1087
diff changeset
327 cxReallocate_(allocator, (void**)(mem), n)
963
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
328
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
329 /**
1610
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
330 * Reallocate a previously allocated block.
963
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
331 *
1610
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
332 * Internal function - do not use.
963
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
333 *
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
334 * @param allocator the allocator
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
335 * @param mem pointer to the pointer to allocated block
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
336 * @param nmemb the number of elements
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
337 * @param size the size of each element
1085
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
338 * @retval zero success
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
339 * @retval non-zero on failure
963
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
340 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1610
diff changeset
341 CX_EXTERN CX_NODISCARD CX_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1610
diff changeset
342 int cxReallocateArray_(const CxAllocator *allocator,
1426
3a89b31f0724 clean up header files and adds support for comparing arbitrary strings with string.h functions
Mike Becker <universe@uap-core.de>
parents: 1424
diff changeset
343 void **mem, size_t nmemb, size_t size);
963
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
344
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
345 /**
1185
d825aca193d3 use reallocate instead of re-allocate
Mike Becker <universe@uap-core.de>
parents: 1180
diff changeset
346 * Reallocate a previously allocated block and changes the pointer in-place,
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 963
diff changeset
347 * if necessary.
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 963
diff changeset
348 * This function acts like cxReallocArray() using the pointer pointed to
1085
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
349 * by @p mem.
963
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
350 *
1085
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
351 * @note Re-allocating a block allocated by a different allocator is undefined.
963
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
352 *
1085
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
353 * @par Error handling
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
354 * @c errno will be set, if the underlying realloc function does so or the
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
355 * multiplication of @p nmemb and @p size overflows.
963
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
356 *
1087
128324af5164 don't document constness of arguments in macros
Mike Becker <universe@uap-core.de>
parents: 1085
diff changeset
357 * @param allocator (@c CxAllocator*) the allocator
1085
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
358 * @param mem (@c void**) pointer to the pointer to allocated block
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
359 * @param nmemb (@c size_t) the number of elements
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
360 * @param size (@c size_t) the size of each element
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
361 * @retval zero success
b8e0b4130cc3 refine docs for allocator.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
362 * @retval non-zero failure
963
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
363 */
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
364 #define cxReallocateArray(allocator, mem, nmemb, size) \
1134
60edcd57d54c fix that some IDEs cannot resolve documentation
Mike Becker <universe@uap-core.de>
parents: 1087
diff changeset
365 cxReallocateArray_(allocator, (void**) (mem), nmemb, size)
963
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
366
2f601274bbac add reallocarray() like functions - resolves #468
Mike Becker <universe@uap-core.de>
parents: 935
diff changeset
367 /**
1610
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
368 * Allocate @p nmemb elements of @p size bytes each, all initialized to zero.
431
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
369 *
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
370 * @param allocator the allocator
1169
6a33a5648027 add documentation for allocator.h
Mike Becker <universe@uap-core.de>
parents: 1134
diff changeset
371 * @param nmemb the number of elements
6a33a5648027 add documentation for allocator.h
Mike Becker <universe@uap-core.de>
parents: 1134
diff changeset
372 * @param size the size of each element in bytes
431
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
373 * @return a pointer to the allocated memory
3d8235c96a27 add documentation to allocator.h
Mike Becker <universe@uap-core.de>
parents: 419
diff changeset
374 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1610
diff changeset
375 CX_EXTERN CX_NONNULL_ARG(1) CX_NODISCARD
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1610
diff changeset
376 CX_MALLOC CX_DEALLOC_UCX CX_ALLOCSIZE(2, 3)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1610
diff changeset
377 void *cxCalloc(const CxAllocator *allocator, size_t nmemb, size_t size);
397
cfc1193b1e65 removes unnecessary cx_allocator typedef
Mike Becker <universe@uap-core.de>
parents: 396
diff changeset
378
1332
dd5d2402d161 implement zalloc() - resolves #679
Mike Becker <universe@uap-core.de>
parents: 1319
diff changeset
379 /**
dd5d2402d161 implement zalloc() - resolves #679
Mike Becker <universe@uap-core.de>
parents: 1319
diff changeset
380 * Allocate @p n bytes of memory and sets every byte to zero.
dd5d2402d161 implement zalloc() - resolves #679
Mike Becker <universe@uap-core.de>
parents: 1319
diff changeset
381 *
dd5d2402d161 implement zalloc() - resolves #679
Mike Becker <universe@uap-core.de>
parents: 1319
diff changeset
382 * @param allocator the allocator
dd5d2402d161 implement zalloc() - resolves #679
Mike Becker <universe@uap-core.de>
parents: 1319
diff changeset
383 * @param n the number of bytes
dd5d2402d161 implement zalloc() - resolves #679
Mike Becker <universe@uap-core.de>
parents: 1319
diff changeset
384 * @return a pointer to the allocated memory
dd5d2402d161 implement zalloc() - resolves #679
Mike Becker <universe@uap-core.de>
parents: 1319
diff changeset
385 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1610
diff changeset
386 CX_EXTERN CX_NODISCARD CX_NONNULL
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1610
diff changeset
387 CX_MALLOC CX_DEALLOC_UCX CX_ALLOCSIZE(2)
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1610
diff changeset
388 void *cxZalloc(const CxAllocator *allocator, size_t n);
1319
aa1f580f8f59 add convenience macros for using the default allocator - relates to #669
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
389
aa1f580f8f59 add convenience macros for using the default allocator - relates to #669
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
390 /**
1610
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
391 * Allocate @p n bytes of memory.
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
392 *
1319
aa1f580f8f59 add convenience macros for using the default allocator - relates to #669
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
393 * Convenience macro that invokes cxMalloc() with the cxDefaultAllocator.
1610
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
394 *
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
395 * @param n (@c size_t) the number of bytes
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
396 * @return (@c void*) a pointer to the allocated memory
1319
aa1f580f8f59 add convenience macros for using the default allocator - relates to #669
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
397 */
1610
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
398 #define cxMallocDefault(n) cxMalloc(cxDefaultAllocator, n)
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
399
1319
aa1f580f8f59 add convenience macros for using the default allocator - relates to #669
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
400 /**
1610
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
401 * Allocate @p n bytes of memory and sets every byte to zero.
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
402 *
1332
dd5d2402d161 implement zalloc() - resolves #679
Mike Becker <universe@uap-core.de>
parents: 1319
diff changeset
403 * Convenience macro that invokes cxZalloc() with the cxDefaultAllocator.
1610
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
404 *
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
405 * @param n (@c size_t) the number of bytes
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
406 * @return (@c void*) a pointer to the allocated memory
1332
dd5d2402d161 implement zalloc() - resolves #679
Mike Becker <universe@uap-core.de>
parents: 1319
diff changeset
407 */
1610
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
408 #define cxZallocDefault(n) cxZalloc(cxDefaultAllocator, n)
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
409
1332
dd5d2402d161 implement zalloc() - resolves #679
Mike Becker <universe@uap-core.de>
parents: 1319
diff changeset
410 /**
1610
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
411 * Allocate @p nmemb elements of @p size bytes each, all initialized to zero.
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
412 *
1319
aa1f580f8f59 add convenience macros for using the default allocator - relates to #669
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
413 * Convenience macro that invokes cxCalloc() with the cxDefaultAllocator.
1610
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
414 *
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
415 * @param nmemb (@c size_t) the number of elements
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
416 * @param size (@c size_t) the size of each element in bytes
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
417 * @return (@c void*) a pointer to the allocated memory
1319
aa1f580f8f59 add convenience macros for using the default allocator - relates to #669
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
418 */
1610
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
419 #define cxCallocDefault(nmemb, size) cxCalloc(cxDefaultAllocator, nmemb, size)
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
420
1319
aa1f580f8f59 add convenience macros for using the default allocator - relates to #669
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
421 /**
1610
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
422 * Reallocate the previously allocated block in @p mem.
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
423 *
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
424 * This function may return the same pointer passed to it if moving
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
425 * the memory was not necessary.
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
426 *
1319
aa1f580f8f59 add convenience macros for using the default allocator - relates to #669
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
427 * Convenience macro that invokes cxRealloc() with the cxDefaultAllocator.
1610
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
428 *
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
429 * @attention This function is bug-prone. Consider using cxReallocateDefault().
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
430 *
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
431 * @param mem (@c void*) pointer to the previously allocated block
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
432 * @param n (@c size_t) the new size in bytes
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
433 * @return (@c void*) a pointer to the reallocated memory
1319
aa1f580f8f59 add convenience macros for using the default allocator - relates to #669
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
434 */
1610
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
435 #define cxReallocDefault(mem, n) cxRealloc(cxDefaultAllocator, mem, n)
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
436
1319
aa1f580f8f59 add convenience macros for using the default allocator - relates to #669
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
437 /**
1610
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
438 * Reallocate a previously allocated block and changes the pointer in-place,
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
439 * if necessary.
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
440 * This function acts like cxRealloc() using the pointer pointed to by @p mem.
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
441 *
1319
aa1f580f8f59 add convenience macros for using the default allocator - relates to #669
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
442 * Convenience macro that invokes cxReallocate() with the cxDefaultAllocator.
1610
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
443 *
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
444 * @note Re-allocating a block allocated by a different allocator is undefined.
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
445 *
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
446 * @par Error handling
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
447 * @c errno will be set if the underlying realloc function does so.
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
448 *
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
449 * @param mem (@c void**) pointer to the pointer to allocated block
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
450 * @param n (@c size_t) the new size in bytes
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
451 * @retval zero success
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
452 * @retval non-zero failure
1319
aa1f580f8f59 add convenience macros for using the default allocator - relates to #669
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
453 */
1610
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
454 #define cxReallocateDefault(mem, n) cxReallocate(cxDefaultAllocator, mem, n)
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
455
1319
aa1f580f8f59 add convenience macros for using the default allocator - relates to #669
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
456 /**
1610
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
457 * Reallocate a previously allocated block and changes the pointer in-place,
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
458 * if necessary.
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
459 * This function acts like cxReallocArray() using the pointer pointed to
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
460 * by @p mem.
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
461 *
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
462 * Convenience macro that invokes cxReallocateArray() with the cxDefaultAllocator.
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
463 *
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
464 * @note Re-allocating a block allocated by a different allocator is undefined.
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
465 *
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
466 * @par Error handling
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
467 * @c errno will be set, if the underlying realloc function does so or the
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
468 * multiplication of @p nmemb and @p size overflows.
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
469 *
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
470 * @param mem (@c void**) pointer to the pointer to allocated block
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
471 * @param nmemb (@c size_t) the number of elements
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
472 * @param size (@c size_t) the size of each element
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
473 * @retval zero success
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
474 * @retval non-zero failure
1319
aa1f580f8f59 add convenience macros for using the default allocator - relates to #669
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
475 */
1610
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
476 #define cxReallocateArrayDefault(mem, nmemb, size) \
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
477 cxReallocateArray(cxDefaultAllocator, mem, nmemb, size)
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
478
1319
aa1f580f8f59 add convenience macros for using the default allocator - relates to #669
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
479 /**
1610
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
480 * Reallocate the previously allocated block in @p mem.
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
481 *
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
482 * Convenience macro that invokes cxReallocArray() with the cxDefaultAllocator.
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
483 *
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
484 * This function may return the same pointer passed to it if moving
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
485 * the memory was not necessary.
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
486 *
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
487 * The size is calculated by multiplying @p nemb and @p size.
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
488 * If that multiplication overflows, this function returns @c NULL, and @c errno
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
489 * will be set.
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
490 *
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
491 * @note Re-allocating a block allocated by a different allocator is undefined.
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
492 *
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
493 * @attention This function is bug-prone. Consider using cxReallocateArrayDefault().
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
494 *
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
495 * @param mem (@c void*) pointer to the previously allocated block
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
496 * @param nmemb (@c size_t) the number of elements
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
497 * @param size (@c size_t) the size of each element
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
498 * @return (@c void*) a pointer to the reallocated memory
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
499 */
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
500 #define cxReallocArrayDefault(mem, nmemb, size) cxReallocArray(cxDefaultAllocator, mem, nmemb, size)
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
501
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
502 /**
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
503 * Free a block of memory.
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
504 *
1554
91fb10c89611 changes cxFreeDefault() from a macro to a function so that it can be used as a simple destructor
Mike Becker <universe@uap-core.de>
parents: 1539
diff changeset
505 * Convenience function that invokes cxFree() with the cxDefaultAllocator.
1610
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
506 *
ce0b0bf7d29c fix missing docstrings for the convenience macros in allocator.h
Mike Becker <universe@uap-core.de>
parents: 1593
diff changeset
507 * @param mem the memory to deallocate
1319
aa1f580f8f59 add convenience macros for using the default allocator - relates to #669
Mike Becker <universe@uap-core.de>
parents: 1318
diff changeset
508 */
1675
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1610
diff changeset
509 CX_EXTERN
36c0fb2b60b2 overhaul all attributes
Mike Becker <universe@uap-core.de>
parents: 1610
diff changeset
510 void cxFreeDefault(void *mem);
416
067aa769796a fix missing extern "C"
Mike Becker <universe@uap-core.de>
parents: 414
diff changeset
511
628
1e2be40f0cb5 use //-style single line comments everywhere
Mike Becker <universe@uap-core.de>
parents: 528
diff changeset
512 #endif // UCX_ALLOCATOR_H

mercurial