2011-02-18 13:58:08 +00:00
|
|
|
/*
|
2008-07-04 17:32:55 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): Geoffrey Bantle.
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2012-02-17 18:59:41 +00:00
|
|
|
#ifndef __BLI_MEMPOOL_H__
|
|
|
|
#define __BLI_MEMPOOL_H__
|
2008-07-04 17:32:55 +00:00
|
|
|
|
2011-10-22 15:35:49 +00:00
|
|
|
/** \file BLI_mempool.h
|
2011-02-18 13:58:08 +00:00
|
|
|
* \ingroup bli
|
|
|
|
* \author Geoffrey Bantle
|
2012-07-14 15:29:45 +00:00
|
|
|
* \brief Simple fast memory allocator for fixed size chunks.
|
2011-02-18 13:58:08 +00:00
|
|
|
*/
|
|
|
|
|
2011-11-16 19:31:42 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
|
2013-09-01 15:01:15 +00:00
|
|
|
#include "BLI_compiler_attrs.h"
|
|
|
|
|
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;
|
|
|
|
|
2012-02-29 15:00:37 +00:00
|
|
|
/* allow_iter allows iteration on this mempool. note: this requires that the
|
|
|
|
* first four bytes of the elements never contain the character string
|
|
|
|
* 'free'. use with care.*/
|
2008-07-04 17:32:55 +00:00
|
|
|
|
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, unsigned int flag) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT;
|
|
|
|
void *BLI_mempool_alloc(BLI_mempool *pool) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
|
|
|
void *BLI_mempool_calloc(BLI_mempool *pool) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
|
|
|
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,
|
2013-09-01 15:01:15 +00:00
|
|
|
const int totelem_reserve) ATTR_NONNULL(1);
|
|
|
|
void BLI_mempool_clear(BLI_mempool *pool) ATTR_NONNULL(1);
|
|
|
|
void BLI_mempool_destroy(BLI_mempool *pool) ATTR_NONNULL(1);
|
|
|
|
int BLI_mempool_count(BLI_mempool *pool) ATTR_NONNULL(1);
|
|
|
|
void *BLI_mempool_findelem(BLI_mempool *pool, unsigned int index) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
2013-08-04 19:40:50 +00: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
|
|
|
|
2013-10-03 14:44:33 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
void BLI_mempool_set_memory_debug(void);
|
|
|
|
#endif
|
|
|
|
|
2011-11-16 19:31:42 +00: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,
|
|
|
|
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
|
2008-07-08 02:22:37 +00:00
|
|
|
|
2012-07-14 12:47:49 +00:00
|
|
|
#endif /* __BLI_MEMPOOL_H__ */
|