| 
									
										
										
										
											2011-02-18 13:58:08 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2008-07-04 17:32:55 +00:00
										 |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							| 
									
										
										
										
											2010-02-12 13:34:04 +00:00
										 |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							| 
									
										
										
										
											2008-07-04 17:32:55 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2008 Blender Foundation. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-06-17 16:32:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-17 18:59:41 +00:00
										 |  |  | #pragma once
 | 
					
						
							| 
									
										
										
										
											2008-07-04 17:32:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 08:08:12 +11:00
										 |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup bli | 
					
						
							| 
									
										
										
										
											2011-02-18 13:58:08 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-08 18:16:39 +02:00
										 |  |  | #include "BLI_compiler_attrs.h"
 | 
					
						
							|  |  |  | #include "BLI_utildefines.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-16 19:31:42 +00:00
										 |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | extern "C" { | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-04 17:32:55 +00:00
										 |  |  | struct BLI_mempool; | 
					
						
							| 
									
										
										
										
											2011-11-16 19:31:42 +00:00
										 |  |  | struct BLI_mempool_chunk; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct BLI_mempool BLI_mempool; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-30 21:32:57 +00:00
										 |  |  | BLI_mempool *BLI_mempool_create(unsigned int esize, | 
					
						
							|  |  |  |                                 unsigned int totelem, | 
					
						
							| 
									
										
										
										
											2013-09-01 15:01:15 +00:00
										 |  |  |                                 unsigned int pchunk, | 
					
						
							| 
									
										
										
										
											2021-06-13 14:47:19 +10:00
										 |  |  |                                 unsigned int flag) | 
					
						
							|  |  |  |     ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL; | 
					
						
							|  |  |  | void *BLI_mempool_alloc(BLI_mempool *pool) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL | 
					
						
							|  |  |  |     ATTR_NONNULL(1); | 
					
						
							|  |  |  | void *BLI_mempool_calloc(BLI_mempool *pool) | 
					
						
							|  |  |  |     ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(1); | 
					
						
							| 
									
										
										
										
											2013-09-01 15:01:15 +00:00
										 |  |  | void BLI_mempool_free(BLI_mempool *pool, void *addr) ATTR_NONNULL(1, 2); | 
					
						
							| 
									
										
										
										
											2013-08-25 16:16:38 +00:00
										 |  |  | void BLI_mempool_clear_ex(BLI_mempool *pool, const int totelem_reserve) ATTR_NONNULL(1); | 
					
						
							| 
									
										
										
										
											2013-09-01 15:01:15 +00:00
										 |  |  | void BLI_mempool_clear(BLI_mempool *pool) ATTR_NONNULL(1); | 
					
						
							|  |  |  | void BLI_mempool_destroy(BLI_mempool *pool) ATTR_NONNULL(1); | 
					
						
							| 
									
										
										
										
											2021-06-30 16:37:14 +10:00
										 |  |  | int BLI_mempool_len(const BLI_mempool *pool) ATTR_NONNULL(1); | 
					
						
							| 
									
										
										
										
											2013-09-01 15:01:15 +00:00
										 |  |  | void *BLI_mempool_findelem(BLI_mempool *pool, unsigned int index) ATTR_WARN_UNUSED_RESULT | 
					
						
							|  |  |  |     ATTR_NONNULL(1); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-01 15:01:15 +00:00
										 |  |  | void BLI_mempool_as_table(BLI_mempool *pool, void **data) ATTR_NONNULL(1, 2); | 
					
						
							|  |  |  | void **BLI_mempool_as_tableN(BLI_mempool *pool, | 
					
						
							|  |  |  |                              const char *allocstr) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT | 
					
						
							|  |  |  |     ATTR_NONNULL(1, 2); | 
					
						
							|  |  |  | void BLI_mempool_as_array(BLI_mempool *pool, void *data) ATTR_NONNULL(1, 2); | 
					
						
							|  |  |  | void *BLI_mempool_as_arrayN(BLI_mempool *pool, | 
					
						
							|  |  |  |                             const char *allocstr) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT | 
					
						
							|  |  |  |     ATTR_NONNULL(1, 2); | 
					
						
							| 
									
										
										
										
											2013-01-30 21:17:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-09 19:23:49 +10:00
										 |  |  | #ifndef NDEBUG
 | 
					
						
							| 
									
										
										
										
											2013-10-03 14:44:33 +00:00
										 |  |  | void BLI_mempool_set_memory_debug(void); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-19 15:17:46 +11:00
										 |  |  | /** iteration stuff.  note: this may easy to produce bugs with */ | 
					
						
							| 
									
										
										
										
											2012-07-14 12:47:49 +00:00
										 |  |  | /* private structure */ | 
					
						
							| 
									
										
										
										
											2011-11-16 19:31:42 +00:00
										 |  |  | typedef struct BLI_mempool_iter { | 
					
						
							|  |  |  |   BLI_mempool *pool; | 
					
						
							|  |  |  |   struct BLI_mempool_chunk *curchunk; | 
					
						
							| 
									
										
										
										
											2013-08-30 21:32:57 +00:00
										 |  |  |   unsigned int curindex; | 
					
						
							| 
									
										
										
										
											2011-11-16 19:31:42 +00:00
										 |  |  | } BLI_mempool_iter; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-01 22:59:18 +00:00
										 |  |  | /* flag */ | 
					
						
							|  |  |  | enum { | 
					
						
							| 
									
										
										
										
											2014-04-05 10:57:32 +11:00
										 |  |  |   BLI_MEMPOOL_NOP = 0, | 
					
						
							| 
									
										
										
										
											2015-08-05 00:21:50 +10:00
										 |  |  |   /** allow iterating on this mempool.
 | 
					
						
							|  |  |  |    * | 
					
						
							| 
									
										
										
										
											2019-04-22 00:54:27 +10:00
										 |  |  |    * \note this requires that the first four bytes of the elements | 
					
						
							|  |  |  |    * never begin with 'free' (#FREEWORD). | 
					
						
							|  |  |  |    * \note order of iteration is only assured to be the | 
					
						
							|  |  |  |    * order of allocation when no chunks have been freed. | 
					
						
							| 
									
										
										
										
											2015-08-05 00:21:50 +10:00
										 |  |  |    */ | 
					
						
							| 
									
										
										
										
											2014-04-05 10:57:32 +11:00
										 |  |  |   BLI_MEMPOOL_ALLOW_ITER = (1 << 0), | 
					
						
							| 
									
										
										
										
											2012-03-01 22:59:18 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-01 15:01:15 +00:00
										 |  |  | void BLI_mempool_iternew(BLI_mempool *pool, BLI_mempool_iter *iter) ATTR_NONNULL(); | 
					
						
							|  |  |  | void *BLI_mempool_iterstep(BLI_mempool_iter *iter) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); | 
					
						
							| 
									
										
										
										
											2011-11-16 19:31:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 |