Blender V4.3
BLI_virtual_array.hh File Reference
#include <optional>
#include "BLI_any.hh"
#include "BLI_array.hh"
#include "BLI_devirtualize_parameters.hh"
#include "BLI_index_mask.hh"
#include "BLI_span.hh"

Go to the source code of this file.

Classes

struct  blender::CommonVArrayInfo
 
class  blender::VArrayImpl< T >
 
class  blender::VMutableArrayImpl< T >
 
class  blender::VArrayImpl_For_Span< T >
 
class  blender::VArrayImpl_For_Span_final< T >
 
class  blender::VArrayImpl_For_ArrayContainer< Container, T >
 
class  blender::VArrayImpl_For_Single< T >
 
class  blender::VArrayImpl_For_Func< T, GetFunc >
 
class  blender::VArrayImpl_For_DerivedSpan< StructT, ElemT, GetFunc, SetFunc >
 
struct  blender::detail::VArrayAnyExtraInfo< T >
 
class  blender::VArrayCommon< T >
 
struct  blender::varray_tag::span
 
struct  blender::varray_tag::single_ref
 
struct  blender::varray_tag::single
 
class  blender::VArray< T >
 
class  blender::VMutableArray< T >
 
class  blender::VArraySpan< T >
 
class  blender::MutableVArraySpan< T >
 
class  blender::SingleAsSpan< T >
 
class  blender::VArrayRef< T >
 
struct  blender::VArrayDevirtualizer< T, UseSingle, UseSpan >
 

Namespaces

namespace  blender
 
namespace  blender::detail
 
namespace  blender::varray_tag
 
namespace  blender::internal
 

Functions

void blender::internal::print_mutable_varray_span_warning ()
 
template<typename T , typename Func >
void blender::devirtualize_varray (const VArray< T > &varray, const Func &func, bool enable=true)
 
template<typename T1 , typename T2 , typename Func >
void blender::devirtualize_varray2 (const VArray< T1 > &varray1, const VArray< T2 > &varray2, const Func &func, bool enable=true)
 

Variables

template<typename T >
constexpr bool blender::is_trivial_extended_v< VArrayImpl_For_Span_final< T > > = true
 
template<typename T >
constexpr bool blender::is_trivial_extended_v< VArrayImpl_For_Single< T > > = is_trivial_extended_v<T>
 
template<typename StructT , typename ElemT , ElemT(*)(const StructT &) GetFunc, void(*)(StructT &, ElemT) SetFunc>
constexpr bool blender::is_trivial_extended_v< VArrayImpl_For_DerivedSpan< StructT, ElemT, GetFunc, SetFunc > > = true
 
template<typename T >
static constexpr bool blender::is_VArray_v = false
 
template<typename T >
static constexpr bool blender::is_VArray_v< VArray< T > > = true
 
template<typename T >
static constexpr bool blender::is_VMutableArray_v = false
 
template<typename T >
static constexpr bool blender::is_VMutableArray_v< VMutableArray< T > > = true
 

Detailed Description

A virtual array is a data structure that behaves similarly to an array, but its elements are accessed through virtual methods. This improves the decoupling of a function from its callers, because it does not have to know exactly how the data is laid out in memory, or if it is stored in memory at all. It could just as well be computed on the fly.

Taking a virtual array as parameter instead of a more specific non-virtual type has some tradeoffs. Access to individual elements of the individual elements is slower due to function call overhead. On the other hand, potential callers don't have to convert the data into the specific format required for the function. This can be a costly conversion if only few of the elements are accessed in the end.

Functions taking a virtual array as input can still optimize for different data layouts. For example, they can check if the array references contiguous memory internally or if it is the same value for all indices. Whether it is worth optimizing for different data layouts in a function has to be decided on a case by case basis. One should always do some benchmarking to see if the increased compile time and binary size is worth it.

Definition in file BLI_virtual_array.hh.