Blender V5.0
geometry_nodes_list.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6
7namespace blender::nodes {
8
10 public:
11 const CPPType &type;
12 void *data;
14
19
20 private:
21 void delete_self_with_data() override
22 {
23 type.destruct_n(this->data, this->size);
24 MEM_delete(this);
25 }
26};
27
29 const int64_t size,
30 const CPPType &type)
31{
33 /* Avoid storing size and type in sharing info if unnecessary. */
35 }
36 return ImplicitSharingPtr<>(MEM_new<ArrayImplicitSharingData>(__func__, data, size, type));
37}
38
40{
42 const CPPType &type = *value.type();
43 const void *value_ptr = type.default_value();
44
45 /* Prefer `calloc` to zeroing after allocation since it is faster. */
46 if (BLI_memory_is_zero(value_ptr, type.size)) {
47 data.data = MEM_calloc_arrayN_aligned(size, type.size, type.alignment, __func__);
48 }
49 else {
50 data.data = MEM_malloc_arrayN_aligned(size, type.size, type.alignment, __func__);
51 type.fill_construct_n(value_ptr, data.data, size);
52 }
53
54 data.sharing_info = sharing_ptr_for_array(data.data, size, type);
55 return data;
56}
57
62
64{
66 data.data = MEM_malloc_arrayN_aligned(size, type.size, type.alignment, __func__);
67 type.default_construct_n(data.data, size);
68 data.sharing_info = sharing_ptr_for_array(data.data, size, type);
69 return data;
70}
71
73{
75 data.data = MEM_malloc_arrayN_aligned(size, type.size, type.alignment, __func__);
76 data.sharing_info = sharing_ptr_for_array(data.data, size, type);
77 return data;
78}
79
81 public:
82 const CPPType &type;
83 void *data;
84
89
90 private:
91 void delete_self_with_data() override
92 {
93 type.destruct(this->data);
94 MEM_delete(this);
95 }
96};
97
99{
100 if (type.is_trivially_destructible) {
101 /* Avoid storing size and type in sharing info if unnecessary. */
103 }
104 return ImplicitSharingPtr<>(MEM_new<SingleImplicitSharingData>(__func__, data, type));
105}
106
108{
110 const CPPType &type = *value.type();
111 data.value = MEM_mallocN_aligned(type.size, type.alignment, __func__);
112 type.copy_construct(value.get(), data.value);
113 data.sharing_info = sharing_ptr_for_value(data.value, type);
114 return data;
115}
116
121
123{
124 MEM_delete(this);
125}
126
128{
129 if (const auto *array_data = std::get_if<ArrayData>(&data_)) {
130 return GVArray::from_span(GSpan(cpp_type_, array_data->data, size_));
131 }
132 if (const auto *single_data = std::get_if<SingleData>(&data_)) {
133 return GVArray::from_single_ref(cpp_type_, size_, single_data->value);
134 }
136 return {};
137}
138
139} // namespace blender::nodes
#define BLI_assert_unreachable()
Definition BLI_assert.h:93
bool BLI_memory_is_zero(const void *arr, size_t size)
BMesh const char void * data
long long int int64_t
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
void default_construct_n(void *ptr, int64_t n) const
void destruct_n(void *ptr, int64_t n) const
void fill_construct_n(const void *value, void *dst, int64_t n) const
void copy_construct(const void *src, void *dst) const
void destruct(void *ptr) const
const void * default_value() const
const CPPType * type() const
static GVArray from_span(GSpan span)
static GVArray from_single_ref(const CPPType &type, int64_t size, const void *value)
ArrayImplicitSharingData(void *data, const int64_t size, const CPPType &type)
static ArrayData ForDefaultValue(const CPPType &type, int64_t size)
static ArrayData ForConstructed(const CPPType &type, int64_t size)
static ArrayData ForUninitialized(const CPPType &type, int64_t size)
static ArrayData ForValue(const GPointer &value, int64_t size)
static SingleData ForValue(const GPointer &value)
static SingleData ForDefaultValue(const CPPType &type)
const DataVariant & data() const
SingleImplicitSharingData(void *data, const CPPType &type)
void * MEM_mallocN_aligned(size_t len, size_t alignment, const char *str)
Definition mallocn.cc:138
void *(* MEM_calloc_arrayN_aligned)(size_t len, size_t size, size_t alignment, const char *str)
Definition mallocn.cc:59
void *(* MEM_malloc_arrayN_aligned)(size_t len, size_t size, size_t alignment, const char *str)
Definition mallocn.cc:55
const ImplicitSharingInfo * info_for_mem_free(void *data)
static ImplicitSharingPtr sharing_ptr_for_array(void *data, const int64_t size, const CPPType &type)
static ImplicitSharingPtr sharing_ptr_for_value(void *data, const CPPType &type)