Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
agg::block_allocator Class Reference

#include <src/agg/agg_array.h>

+ Collaboration diagram for agg::block_allocator:

Classes

struct  block_type
 

Public Member Functions

void remove_all ()
 
 ~block_allocator ()
 
 block_allocator (unsigned block_size, unsigned block_ptr_inc=256-8)
 
int8uallocate (unsigned size, unsigned alignment=1)
 

Private Member Functions

void allocate_block (unsigned size)
 

Private Attributes

unsigned m_block_size
 
unsigned m_block_ptr_inc
 
unsigned m_num_blocks
 
unsigned m_max_blocks
 
block_typem_blocks
 
int8um_buf_ptr
 
unsigned m_rest
 

Detailed Description


Class Documentation

◆ agg::block_allocator::block_type

struct agg::block_allocator::block_type
Class Members
int8u * data
unsigned size

Constructor & Destructor Documentation

◆ ~block_allocator()

agg::block_allocator::~block_allocator ( )
inline
810 {
811 remove_all();
812 }
void remove_all()
Definition agg_array.h:790

References remove_all().

+ Here is the call graph for this function:

◆ block_allocator()

agg::block_allocator::block_allocator ( unsigned  block_size,
unsigned  block_ptr_inc = 256-8 
)
inline
814 :
815 m_block_size(block_size),
816 m_block_ptr_inc(block_ptr_inc),
817 m_num_blocks(0),
818 m_max_blocks(0),
819 m_blocks(0),
820 m_buf_ptr(0),
821 m_rest(0)
822 {
823 }
unsigned m_max_blocks
Definition agg_array.h:889
unsigned m_block_ptr_inc
Definition agg_array.h:887
unsigned m_num_blocks
Definition agg_array.h:888
int8u * m_buf_ptr
Definition agg_array.h:891
block_type * m_blocks
Definition agg_array.h:890
unsigned m_block_size
Definition agg_array.h:886
unsigned m_rest
Definition agg_array.h:892

Member Function Documentation

◆ allocate()

int8u * agg::block_allocator::allocate ( unsigned  size,
unsigned  alignment = 1 
)
inline
827 {
828 if(size == 0) return 0;
829 if(size <= m_rest)
830 {
831 int8u* ptr = m_buf_ptr;
832 if(alignment > 1)
833 {
834 unsigned align =
835 (alignment - unsigned((size_t)ptr) % alignment) % alignment;
836
837 size += align;
838 ptr += align;
839 if(size <= m_rest)
840 {
841 m_rest -= size;
842 m_buf_ptr += size;
843 return ptr;
844 }
845 allocate_block(size);
846 return allocate(size - align, alignment);
847 }
848 m_rest -= size;
849 m_buf_ptr += size;
850 return ptr;
851 }
852 allocate_block(size + alignment - 1);
853 return allocate(size, alignment);
854 }
int8u * allocate(unsigned size, unsigned alignment=1)
Definition agg_array.h:826
void allocate_block(unsigned size)
Definition agg_array.h:858
constexpr auto size(const C &c) -> decltype(c.size())
Definition span.hpp:183
AGG_INT8U int8u
Definition agg_basics.h:120

References allocate(), allocate_block(), m_buf_ptr, and m_rest.

Referenced by allocate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ allocate_block()

void agg::block_allocator::allocate_block ( unsigned  size)
inlineprivate
859 {
860 if(size < m_block_size) size = m_block_size;
862 {
863 block_type* new_blocks =
865
866 if(m_blocks)
867 {
868 memcpy(new_blocks,
869 m_blocks,
870 m_num_blocks * sizeof(block_type));
872 }
873 m_blocks = new_blocks;
875 }
876
879 m_buf_ptr =
881
882 m_num_blocks++;
883 m_rest = size;
884 }
unsigned size
Definition agg_array.h:786
int8u * data
Definition agg_array.h:785
static T * allocate(unsigned num)
Definition agg_basics.h:38
static void deallocate(T *ptr, unsigned)
Definition agg_basics.h:39

References agg::pod_allocator< T >::allocate(), agg::block_allocator::block_type::data, agg::pod_allocator< T >::deallocate(), m_block_ptr_inc, m_block_size, m_blocks, m_buf_ptr, m_max_blocks, m_num_blocks, m_rest, and agg::block_allocator::block_type::size.

Referenced by allocate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ remove_all()

void agg::block_allocator::remove_all ( )
inline
791 {
792 if(m_num_blocks)
793 {
794 block_type* blk = m_blocks + m_num_blocks - 1;
795 while(m_num_blocks--)
796 {
797 pod_allocator<int8u>::deallocate(blk->data, blk->size);
798 --blk;
799 }
801 }
802 m_num_blocks = 0;
803 m_max_blocks = 0;
804 m_blocks = 0;
805 m_buf_ptr = 0;
806 m_rest = 0;
807 }

References agg::block_allocator::block_type::data, agg::pod_allocator< T >::deallocate(), m_blocks, m_buf_ptr, m_max_blocks, m_num_blocks, m_rest, and agg::block_allocator::block_type::size.

Referenced by ~block_allocator().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_block_ptr_inc

unsigned agg::block_allocator::m_block_ptr_inc
private

Referenced by allocate_block().

◆ m_block_size

unsigned agg::block_allocator::m_block_size
private

Referenced by allocate_block().

◆ m_blocks

block_type* agg::block_allocator::m_blocks
private

Referenced by allocate_block(), and remove_all().

◆ m_buf_ptr

int8u* agg::block_allocator::m_buf_ptr
private

◆ m_max_blocks

unsigned agg::block_allocator::m_max_blocks
private

Referenced by allocate_block(), and remove_all().

◆ m_num_blocks

unsigned agg::block_allocator::m_num_blocks
private

Referenced by allocate_block(), and remove_all().

◆ m_rest

unsigned agg::block_allocator::m_rest
private

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