Blender V4.5
blender::LinearAllocator< Allocator > Class Template Reference

#include <BLI_linear_allocator.hh>

Inherits blender::NonCopyable, and blender::NonMovable.

Inherited by blender::index_mask::IndexMaskMemory.

Public Member Functions

 LinearAllocator ()
 
 ~LinearAllocator ()
 
void * allocate (const int64_t size, const int64_t alignment)
 
template<typename T >
Tallocate ()
 
void * allocate (const CPPType &type)
 
template<typename T >
MutableSpan< Tallocate_array (int64_t size)
 
void * allocate_array (const CPPType &type, const int64_t size)
 
template<typename T , typename... Args>
destruct_ptr< Tconstruct (Args &&...args)
 
template<typename T , typename... Args>
MutableSpan< Tconstruct_array (int64_t size, Args &&...args)
 
template<typename T >
MutableSpan< Tconstruct_array_copy (Span< T > src)
 
StringRefNull copy_string (StringRef str)
 
MutableSpan< void * > allocate_elements_and_pointer_array (int64_t element_amount, int64_t element_size, int64_t element_alignment)
 
template<typename T , typename... Args>
Span< T * > construct_elements_and_pointer_array (int64_t n, Args &&...args)
 
void provide_buffer (void *buffer, const int64_t size)
 
template<size_t Size, size_t Alignment>
void provide_buffer (AlignedBuffer< Size, Alignment > &aligned_buffer)
 
void free_end_of_previous_allocation (const int64_t original_allocation_size, const void *free_after)
 
void transfer_ownership_from (LinearAllocator<> &other)
 

Detailed Description

template<typename Allocator = GuardedAllocator>
class blender::LinearAllocator< Allocator >

If enabled, LinearAllocator keeps track of how much memory it owns and how much it has allocated. A linear allocator is the simplest form of an allocator. It never reuses any memory, and therefore does not need a deallocation method. It simply hands out consecutive buffers of memory. When the current buffer is full, it allocates a new larger buffer and continues.

Definition at line 29 of file BLI_linear_allocator.hh.

Constructor & Destructor Documentation

◆ LinearAllocator()

template<typename Allocator = GuardedAllocator>
blender::LinearAllocator< Allocator >::LinearAllocator ( )
inline

Definition at line 47 of file BLI_linear_allocator.hh.

◆ ~LinearAllocator()

template<typename Allocator = GuardedAllocator>
blender::LinearAllocator< Allocator >::~LinearAllocator ( )
inline

Definition at line 53 of file BLI_linear_allocator.hh.

References ptr.

Member Function Documentation

◆ allocate() [1/3]

◆ allocate() [2/3]

template<typename Allocator = GuardedAllocator>
void * blender::LinearAllocator< Allocator >::allocate ( const CPPType & type)
inline

Same as above but uses a runtime #CPPType.

Definition at line 105 of file BLI_linear_allocator.hh.

References blender::CPPType::alignment, blender::LinearAllocator< Allocator >::allocate(), and blender::CPPType::size.

◆ allocate() [3/3]

◆ allocate_array() [1/2]

template<typename Allocator = GuardedAllocator>
void * blender::LinearAllocator< Allocator >::allocate_array ( const CPPType & type,
const int64_t size )
inline

Same as above but uses a runtime #CPPType.

Definition at line 122 of file BLI_linear_allocator.hh.

References blender::CPPType::alignment, blender::LinearAllocator< Allocator >::allocate(), blender::CPPType::size, and size().

◆ allocate_array() [2/2]

◆ allocate_elements_and_pointer_array()

template<typename Allocator = GuardedAllocator>
MutableSpan< void * > blender::LinearAllocator< Allocator >::allocate_elements_and_pointer_array ( int64_t element_amount,
int64_t element_size,
int64_t element_alignment )
inline

◆ construct()

template<typename Allocator = GuardedAllocator>
template<typename T , typename... Args>
destruct_ptr< T > blender::LinearAllocator< Allocator >::construct ( Args &&... args)
inline

Construct an instance of T in memory provided by this allocator.

Arguments passed to this method will be forwarded to the constructor of T.

You must not call delete on the returned value. Instead, only the destructor has to be called.

Definition at line 135 of file BLI_linear_allocator.hh.

References blender::LinearAllocator< Allocator >::allocate(), T, and value.

Referenced by blender::fn::lazy_function::Graph::add_function(), blender::fn::lazy_function::Graph::add_input(), blender::deg::Depsgraph::add_new_relation(), blender::fn::lazy_function::Graph::add_output(), blender::linear_allocator::ChunkedList< T, SegmentCapacity >::append_as(), blender::ResourceScope::construct(), blender::fn::multi_function::Procedure::construct_function(), blender::nodes::evaluate_closure_eagerly(), blender::bke::ComputeContextCache::for_any_uncached(), blender::nodes::GeoNodesUserData::get_local(), blender::nodes::geo_eval_log::GeoNodesLog::get_local_tree_logger(), blender::fn::lazy_function::Graph::Graph(), blender::fn::lazy_function::GraphExecutor::init_storage(), blender::nodes::LazyFunctionForEvaluateClosureNode::init_storage(), blender::nodes::LazyFunctionForForeachGeometryElementZone::init_storage(), blender::nodes::LazyFunctionForGroupNode::init_storage(), blender::nodes::LazyFunctionForRepeatZone::init_storage(), blender::nodes::geo_eval_log::GeoTreeLogger::log_value(), blender::nodes::geo_eval_log::GeoTreeLogger::log_viewer_node(), blender::fn::multi_function::Procedure::new_branch_instruction(), blender::fn::multi_function::Procedure::new_call_instruction(), blender::fn::multi_function::Procedure::new_destruct_instruction(), blender::fn::multi_function::Procedure::new_dummy_instruction(), blender::fn::multi_function::Procedure::new_return_instruction(), blender::fn::multi_function::Procedure::new_variable(), and blender::tests::TEST().

◆ construct_array()

template<typename Allocator = GuardedAllocator>
template<typename T , typename... Args>
MutableSpan< T > blender::LinearAllocator< Allocator >::construct_array ( int64_t size,
Args &&... args )
inline

Construct multiple instances of a type in an array. The constructor of is called with the given arguments. The caller is responsible for calling the destructor (and not delete) on the constructed elements.

Definition at line 148 of file BLI_linear_allocator.hh.

References blender::LinearAllocator< Allocator >::allocate_array(), size(), and T.

Referenced by blender::tests::TEST().

◆ construct_array_copy()

◆ construct_elements_and_pointer_array()

template<typename Allocator = GuardedAllocator>
template<typename T , typename... Args>
Span< T * > blender::LinearAllocator< Allocator >::construct_elements_and_pointer_array ( int64_t n,
Args &&... args )
inline

◆ copy_string()

◆ free_end_of_previous_allocation()

template<typename Allocator = GuardedAllocator>
void blender::LinearAllocator< Allocator >::free_end_of_previous_allocation ( const int64_t original_allocation_size,
const void * free_after )
inline

Some algorithms can be implemented more efficiently by over-allocating the destination memory a bit. This allows the algorithm not to worry about having enough memory. Generally, this can be a useful strategy if the actual required memory is not known in advance, but an upper bound can be found. Ideally, one can free the over-allocated memory in the end again to reduce memory consumption.

A linear allocator generally does allow freeing any memory. However, there is one exception. One can free the end of the last allocation (but not any previous allocation). While uses of this approach are quite limited, it's still the best option in some situations.

Definition at line 241 of file BLI_linear_allocator.hh.

References BLI_assert.

Referenced by blender::index_mask::evaluate_exact_with_indices().

◆ provide_buffer() [1/2]

template<typename Allocator = GuardedAllocator>
template<size_t Size, size_t Alignment>
void blender::LinearAllocator< Allocator >::provide_buffer ( AlignedBuffer< Size, Alignment > & aligned_buffer)
inline

◆ provide_buffer() [2/2]

◆ transfer_ownership_from()

template<typename Allocator = GuardedAllocator>
void blender::LinearAllocator< Allocator >::transfer_ownership_from ( LinearAllocator<> & other)
inline

This allocator takes ownership of the buffers owned by other. Therefor, when other is destructed, memory allocated using it is not freed.

Note that the caller is responsible for making sure that buffers passed into provide_buffer of other live at least as long as this allocator.

Definition at line 269 of file BLI_linear_allocator.hh.

References blender::Vector< T, InlineBufferCapacity, Allocator >::clear(), and blender::Vector< T, InlineBufferCapacity, Allocator >::extend().

Referenced by blender::index_mask::evaluate_short_unknown_segments_exactly(), blender::index_mask::ParallelSegmentsCollector::reduce(), and blender::tests::TEST().


The documentation for this class was generated from the following file: