2019-05-07 17:52:57 +02: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,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2008 Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* \ingroup bli
|
|
|
|
*/
|
|
|
|
|
2020-05-08 18:16:39 +02:00
|
|
|
#include "BLI_compiler_attrs.h"
|
|
|
|
|
2019-05-07 17:52:57 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2019-05-31 01:45:41 +02:00
|
|
|
#define BLI_MEM_BLOCK_CHUNK_SIZE (1 << 15) /* 32KiB */
|
|
|
|
|
2019-05-07 17:52:57 +02:00
|
|
|
struct BLI_memblock;
|
|
|
|
|
|
|
|
typedef struct BLI_memblock BLI_memblock;
|
2019-05-13 15:57:03 +02:00
|
|
|
typedef void (*MemblockValFreeFP)(void *val);
|
2019-05-07 17:52:57 +02:00
|
|
|
|
2019-05-31 01:45:41 +02:00
|
|
|
BLI_memblock *BLI_memblock_create_ex(uint elem_size, uint chunk_size) ATTR_WARN_UNUSED_RESULT;
|
|
|
|
void *BLI_memblock_alloc(BLI_memblock *mblk) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
* Reset elem count to 0 but keep as much memory allocated needed
|
|
|
|
* for at least the previous elem count.
|
|
|
|
*/
|
2020-09-04 20:59:13 +02:00
|
|
|
void BLI_memblock_clear(BLI_memblock *mblk, MemblockValFreeFP free_callback) ATTR_NONNULL(1);
|
2019-05-13 15:57:03 +02:00
|
|
|
void BLI_memblock_destroy(BLI_memblock *mblk, MemblockValFreeFP free_callback) ATTR_NONNULL(1);
|
2019-05-07 17:52:57 +02:00
|
|
|
|
2019-05-31 01:45:41 +02:00
|
|
|
#define BLI_memblock_create(elem_size) BLI_memblock_create_ex(elem_size, BLI_MEM_BLOCK_CHUNK_SIZE)
|
|
|
|
|
2019-05-07 17:52:57 +02:00
|
|
|
typedef struct BLI_memblock_iter {
|
2019-05-21 00:54:03 +02:00
|
|
|
void **chunk_list;
|
|
|
|
int cur_index;
|
|
|
|
int end_index;
|
|
|
|
int chunk_max_ofs;
|
|
|
|
int chunk_idx;
|
|
|
|
int elem_size;
|
|
|
|
int elem_ofs;
|
2019-05-07 17:52:57 +02:00
|
|
|
} BLI_memblock_iter;
|
|
|
|
|
2020-09-04 20:59:13 +02:00
|
|
|
void BLI_memblock_iternew(BLI_memblock *mblk, BLI_memblock_iter *iter) ATTR_NONNULL();
|
2019-05-07 17:52:57 +02:00
|
|
|
void *BLI_memblock_iterstep(BLI_memblock_iter *iter) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
|
|
|
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
* Direct access. elem is element index inside the chosen chunk.
|
|
|
|
* Double usage: You can set chunk to 0 and set the absolute elem index.
|
|
|
|
* The correct chunk will be retrieve.
|
|
|
|
*/
|
2019-05-31 01:45:41 +02:00
|
|
|
void *BLI_memblock_elem_get(BLI_memblock *mblk, int chunk, int elem) ATTR_WARN_UNUSED_RESULT
|
|
|
|
ATTR_NONNULL();
|
|
|
|
|
2019-05-07 17:52:57 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|