src/cx/allocator.h

changeset 1431
1ec36e652e57
parent 1426
3a89b31f0724
equal deleted inserted replaced
1430:5917ed4e5a79 1431:1ec36e652e57
117 * @param data an optional pointer to custom data 117 * @param data an optional pointer to custom data
118 * @param memory a pointer to the object to destruct 118 * @param memory a pointer to the object to destruct
119 */ 119 */
120 typedef void (*cx_destructor_func2)(void *data, void *memory); 120 typedef void (*cx_destructor_func2)(void *data, void *memory);
121 121
122
123 /**
124 * Function pointer type for clone functions.
125 *
126 * A clone function is supposed to create a deep copy of the memory pointed to
127 * by the @p source pointer.
128 * If the @p target pointer is non-null, the clone function is supposed to store
129 * the copy into that memory region.
130 * Otherwise, the clone function shall use the specified @p allocator to create
131 * a new object.
132 *
133 * The return value of a clone function is always a pointer to the target
134 * memory region, or @c NULL if any allocation failed.
135 * A clone function SHOULD NOT fail for any other reason than an allocation
136 * failure.
137 *
138 * @param target the target memory or @c NULL, if memory shall be allocated
139 * @param source the source memory
140 * @param allocator the allocator that shall be used
141 * @param data optional additional data
142 * @return either the specified @p target, a pointer to the allocated memory,
143 * or @c NULL, if any error occurred
144 */
145 typedef void*(cx_clone_func)(void *target, const void *source,
146 const CxAllocator *allocator, void *data);
147
122 /** 148 /**
123 * Reallocate a previously allocated block and changes the pointer in-place, 149 * Reallocate a previously allocated block and changes the pointer in-place,
124 * if necessary. 150 * if necessary.
125 * 151 *
126 * @note This will use stdlib reallocate and @em not the cxDefaultAllocator. 152 * @note This will use stdlib reallocate and @em not the cxDefaultAllocator.
133 * @retval zero success 159 * @retval zero success
134 * @retval non-zero failure 160 * @retval non-zero failure
135 * @see cx_reallocatearray() 161 * @see cx_reallocatearray()
136 */ 162 */
137 cx_attr_nonnull cx_attr_nodiscard 163 cx_attr_nonnull cx_attr_nodiscard
138 CX_EXPORT int cx_reallocate_( 164 CX_EXPORT int cx_reallocate_(void **mem, size_t n);
139 void **mem,
140 size_t n
141 );
142 165
143 /** 166 /**
144 * Reallocate a previously allocated block and changes the pointer in-place, 167 * Reallocate a previously allocated block and changes the pointer in-place,
145 * if necessary. 168 * if necessary.
146 * 169 *

mercurial