Blender V5.3
BLI_memarena.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include <cstddef>
12
13#include "BLI_compiler_attrs.hh"
14
15#include "MEM_guardedalloc.h"
16
17namespace blender {
18
23#define BLI_MEMARENA_STD_BUFSIZE MEM_SIZE_OPTIMAL(1 << 14)
24
25struct MemArena;
26
27MemArena *BLI_memarena_new(size_t bufsize,
30void BLI_memarena_free(MemArena *ma) ATTR_NONNULL(1);
31void BLI_memarena_use_malloc(MemArena *ma) ATTR_NONNULL(1);
32void BLI_memarena_use_calloc(MemArena *ma) ATTR_NONNULL(1);
33void BLI_memarena_use_align(MemArena *ma, size_t align) ATTR_NONNULL(1);
34void *BLI_memarena_alloc(MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT
36void *BLI_memarena_calloc(MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT
38
42template<typename T>
44 const size_t num = 1)
45{
46 static_assert(std::is_trivial_v<T>,
47 "Only trivial types may be allocated with BLI_memarena_alloc");
48 return static_cast<T *>(BLI_memarena_alloc(ma, sizeof(T) * num));
49}
50template<typename T>
52 const size_t num = 1)
53{
54 static_assert(std::is_trivial_v<T>,
55 "Only trivial types may be allocated with BLI_memarena_calloc");
56 return static_cast<T *>(BLI_memarena_calloc(ma, sizeof(T) * num));
57}
58
69void BLI_memarena_merge(MemArena *ma_dst, MemArena *ma_src) ATTR_NONNULL(1, 2);
70
76
77} // namespace blender
#define ATTR_MALLOC
#define ATTR_ALLOC_SIZE(...)
#define ATTR_WARN_UNUSED_RESULT
#define ATTR_RETURNS_NONNULL
#define ATTR_NONNULL(...)
Read Blender memory allocation and freeing.
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
#define T
BMesh Iterators.
void BLI_memarena_merge(MemArena *ma_dst, MemArena *ma_src)
void BLI_memarena_use_calloc(MemArena *ma) ATTR_NONNULL(1)
MemArena * BLI_memarena_new(size_t bufsize, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(2) ATTR_MALLOC
void BLI_memarena_use_align(MemArena *ma, size_t align) ATTR_NONNULL(1)
void BLI_memarena_use_malloc(MemArena *ma) ATTR_NONNULL(1)
void BLI_memarena_clear(MemArena *ma) ATTR_NONNULL(1)
ATTR_WARN_UNUSED_RESULT const size_t num
void * BLI_memarena_alloc(MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_ALLOC_SIZE(2)
void ATTR_NONNULL(1, 2)
void * BLI_memarena_calloc(MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_ALLOC_SIZE(2)
void BLI_memarena_free(MemArena *ma) ATTR_NONNULL(1)