Blender V5.3
BLI_dynamic_stack_buffer.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
10
11#include "BLI_assert.hh"
12
13#include "MEM_guardedalloc.h"
14
15namespace blender {
16
24template<size_t ReservedSize = 64, size_t ReservedAlignment = 64>
25class alignas(ReservedAlignment) DynamicStackBuffer {
26 private:
27 /* Don't create an empty array. This causes problems with some compilers. */
28 char reserved_buffer_[(ReservedSize > 0) ? ReservedSize : 1];
29 void *buffer_;
30
31 public:
32 DynamicStackBuffer(const int64_t size, const int64_t alignment)
33 {
34 BLI_assert(size >= 0);
35 BLI_assert(alignment >= 0);
36 if (size <= ReservedSize && alignment <= ReservedAlignment) {
37 buffer_ = reserved_buffer_;
38 }
39 else {
40 buffer_ = MEM_new_uninitialized_aligned(size, alignment, __func__);
41 }
42 }
44 {
45 if (buffer_ != reserved_buffer_) {
46 MEM_delete_void(buffer_);
47 }
48 }
49
50 /* Don't allow any copying or moving of this type. */
51 DynamicStackBuffer(const DynamicStackBuffer &other) = delete;
55
56 void *buffer() const
57 {
58 return buffer_;
59 }
60};
61
62} // namespace blender
Read Blender memory allocation and freeing.
DynamicStackBuffer & operator=(const DynamicStackBuffer &other)=delete
DynamicStackBuffer & operator=(DynamicStackBuffer &&other)=delete
DynamicStackBuffer(const DynamicStackBuffer &other)=delete
DynamicStackBuffer(const int64_t size, const int64_t alignment)
DynamicStackBuffer(DynamicStackBuffer &&other)=delete
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
__int64 int64_t
Definition BKE_text.h:90
void MEM_delete_void(void *vmemh)
void * MEM_new_uninitialized_aligned(size_t len, size_t alignment, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(3)