Blender
V5.3
source
blender
blenlib
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
17
namespace
blender
{
18
23
#define BLI_MEMARENA_STD_BUFSIZE MEM_SIZE_OPTIMAL(1 << 14)
24
25
struct
MemArena;
26
27
MemArena *
BLI_memarena_new
(
size_t
bufsize,
28
const
char
*name)
ATTR_WARN_UNUSED_RESULT
ATTR_RETURNS_NONNULL
29
ATTR_NONNULL
(2)
ATTR_MALLOC
;
30
void
BLI_memarena_free
(MemArena *ma)
ATTR_NONNULL
(1);
31
void
BLI_memarena_use_malloc
(MemArena *ma)
ATTR_NONNULL
(1);
32
void
BLI_memarena_use_calloc
(MemArena *ma)
ATTR_NONNULL
(1);
33
void
BLI_memarena_use_align
(MemArena *ma,
size_t
align)
ATTR_NONNULL
(1);
34
void
*
BLI_memarena_alloc
(MemArena *ma,
size_t
size
)
ATTR_WARN_UNUSED_RESULT
35
ATTR_NONNULL
(1)
ATTR_MALLOC
ATTR_ALLOC_SIZE
(2);
36
void
*
BLI_memarena_calloc
(MemArena *ma,
size_t
size
)
ATTR_WARN_UNUSED_RESULT
37
ATTR_NONNULL
(1)
ATTR_MALLOC
ATTR_ALLOC_SIZE
(2);
38
42
template<typename
T
>
43
ATTR_WARN_UNUSED_RESULT
ATTR_NONNULL
(1)
ATTR_MALLOC
T
*
BLI_memarena_alloc
(MemArena *ma,
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
}
50
template
<
typename
T>
51
ATTR_WARN_UNUSED_RESULT
ATTR_NONNULL
(1)
ATTR_MALLOC
T
*
BLI_memarena_calloc
(MemArena *ma,
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
69
void
BLI_memarena_merge
(
MemArena
*ma_dst,
MemArena
*ma_src)
ATTR_NONNULL
(1, 2);
70
75
void
BLI_memarena_clear
(
MemArena
*ma)
ATTR_NONNULL
(1);
76
77
}
// namespace blender
ATTR_MALLOC
#define ATTR_MALLOC
ATTR_ALLOC_SIZE
#define ATTR_ALLOC_SIZE(...)
ATTR_WARN_UNUSED_RESULT
#define ATTR_WARN_UNUSED_RESULT
ATTR_RETURNS_NONNULL
#define ATTR_RETURNS_NONNULL
ATTR_NONNULL
#define ATTR_NONNULL(...)
BLI_compiler_attrs.hh
MEM_guardedalloc.h
Read Blender memory allocation and freeing.
size
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition
btDbvt.cpp:52
T
#define T
Definition
mball_tessellate.cc:277
blender
BMesh Iterators.
Definition
ANIM_action.hh:30
blender::BLI_memarena_merge
void BLI_memarena_merge(MemArena *ma_dst, MemArena *ma_src)
Definition
BLI_memarena.cc:184
blender::BLI_memarena_use_calloc
void BLI_memarena_use_calloc(MemArena *ma) ATTR_NONNULL(1)
Definition
BLI_memarena.cc:85
blender::BLI_memarena_new
MemArena * BLI_memarena_new(size_t bufsize, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(2) ATTR_MALLOC
Definition
BLI_memarena.cc:73
blender::BLI_memarena_use_align
void BLI_memarena_use_align(MemArena *ma, size_t align) ATTR_NONNULL(1)
Definition
BLI_memarena.cc:95
blender::BLI_memarena_use_malloc
void BLI_memarena_use_malloc(MemArena *ma) ATTR_NONNULL(1)
Definition
BLI_memarena.cc:90
blender::BLI_memarena_clear
void BLI_memarena_clear(MemArena *ma) ATTR_NONNULL(1)
Definition
BLI_memarena.cc:225
blender::num
ATTR_WARN_UNUSED_RESULT const size_t num
Definition
BLI_memarena.hh:44
blender::BLI_memarena_alloc
void * BLI_memarena_alloc(MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_ALLOC_SIZE(2)
Definition
BLI_memarena.cc:125
blender::ATTR_NONNULL
void ATTR_NONNULL(1, 2)
blender::BLI_memarena_calloc
void * BLI_memarena_calloc(MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_ALLOC_SIZE(2)
Definition
BLI_memarena.cc:170
blender::BLI_memarena_free
void BLI_memarena_free(MemArena *ma) ATTR_NONNULL(1)
Definition
BLI_memarena.cc:103
blender::MemArena
Definition
BLI_memarena.cc:47
Generated on
for Blender by
doxygen
1.18.0