1 /* |
1 /* |
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
3 * |
3 * |
4 * Copyright 2015 Olaf Wintermann. All rights reserved. |
4 * Copyright 2016 Olaf Wintermann. All rights reserved. |
5 * |
5 * |
6 * Redistribution and use in source and binary forms, with or without |
6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions are met: |
7 * modification, are permitted provided that the following conditions are met: |
8 * |
8 * |
9 * 1. Redistributions of source code must retain the above copyright |
9 * 1. Redistributions of source code must retain the above copyright |
125 void *ucx_mempool_calloc(UcxMempool *pool, size_t nelem, size_t elsize); |
125 void *ucx_mempool_calloc(UcxMempool *pool, size_t nelem, size_t elsize); |
126 |
126 |
127 /** |
127 /** |
128 * Reallocates pooled memory. |
128 * Reallocates pooled memory. |
129 * |
129 * |
130 * If the memory to be reallocated is not contained by the specified pool, this |
130 * If the memory to be reallocated is not contained by the specified pool, the |
131 * function will possibly fail. In case the memory had to be moved to another |
131 * behavior is undefined. |
132 * location, this function will print out a message to <code>stderr</code> |
|
133 * and exit the program with error code <code>EXIT_FAILURE</code>. |
|
134 * |
132 * |
135 * @param pool the memory pool |
133 * @param pool the memory pool |
136 * @param ptr a pointer to the memory that shall be reallocated |
134 * @param ptr a pointer to the memory that shall be reallocated |
137 * @param n the new size of the memory |
135 * @param n the new size of the memory |
138 * @return a pointer to the new location of the memory |
136 * @return a pointer to the new location of the memory |
144 * Frees pooled memory. |
142 * Frees pooled memory. |
145 * |
143 * |
146 * Before freeing the memory, the specified destructor function (if any) |
144 * Before freeing the memory, the specified destructor function (if any) |
147 * is called. |
145 * is called. |
148 * |
146 * |
149 * If you specify memory, that is not pooled by the specified memory pool, this |
147 * If you specify memory, that is not pooled by the specified memory pool, the |
150 * is considered as a severe error and an error message is written to |
148 * behavior is undefined. |
151 * <code>stderr</code> and the application is shut down with code |
|
152 * <code>EXIT_FAILURE</code>. |
|
153 * |
149 * |
154 * @param pool the memory pool |
150 * @param pool the memory pool |
155 * @param ptr a pointer to the memory that shall be freed |
151 * @param ptr a pointer to the memory that shall be freed |
156 * @see ucx_mempool_set_destr() |
152 * @see ucx_mempool_set_destr() |
157 */ |
153 */ |
178 * |
174 * |
179 * The destructor is automatically called when the memory is freed or the |
175 * The destructor is automatically called when the memory is freed or the |
180 * pool is destroyed. |
176 * pool is destroyed. |
181 * |
177 * |
182 * The only requirement for the specified memory is, that it <b>MUST</b> be |
178 * The only requirement for the specified memory is, that it <b>MUST</b> be |
183 * pooled memory by an UcxMempool or an element-compatible mempool. The pointer |
179 * pooled memory by a UcxMempool or an element-compatible mempool. The pointer |
184 * to the destructor function is saved in a reserved area before the actual |
180 * to the destructor function is saved in a reserved area before the actual |
185 * memory. |
181 * memory. |
186 * |
182 * |
187 * @param ptr pooled memory |
183 * @param ptr pooled memory |
188 * @param func a pointer to the destructor function |
184 * @param func a pointer to the destructor function |