Blender  V3.3
Typedefs | Functions
BLI_array_store.h File Reference

Efficient in-memory storage of multiple similar arrays. More...

Go to the source code of this file.

Typedefs

typedef struct BArrayState BArrayState
 
typedef struct BArrayStore BArrayStore
 

Functions

BArrayStoreBLI_array_store_create (unsigned int stride, unsigned int chunk_count)
 
void BLI_array_store_destroy (BArrayStore *bs)
 
void BLI_array_store_clear (BArrayStore *bs)
 
size_t BLI_array_store_calc_size_expanded_get (const BArrayStore *bs)
 
size_t BLI_array_store_calc_size_compacted_get (const BArrayStore *bs)
 
BArrayStateBLI_array_store_state_add (BArrayStore *bs, const void *data, size_t data_len, const BArrayState *state_reference)
 
void BLI_array_store_state_remove (BArrayStore *bs, BArrayState *state)
 
size_t BLI_array_store_state_size_get (BArrayState *state)
 
void BLI_array_store_state_data_get (BArrayState *state, void *data)
 
voidBLI_array_store_state_data_get_alloc (BArrayState *state, size_t *r_data_len)
 
bool BLI_array_store_is_valid (BArrayStore *bs)
 

Detailed Description

Efficient in-memory storage of multiple similar arrays.

Definition in file BLI_array_store.h.

Typedef Documentation

◆ BArrayState

typedef struct BArrayState BArrayState

Definition at line 1 of file BLI_array_store.h.

◆ BArrayStore

typedef struct BArrayStore BArrayStore

Definition at line 1 of file BLI_array_store.h.

Function Documentation

◆ BLI_array_store_calc_size_compacted_get()

size_t BLI_array_store_calc_size_compacted_get ( const BArrayStore bs)

◆ BLI_array_store_calc_size_expanded_get()

size_t BLI_array_store_calc_size_expanded_get ( const BArrayStore bs)

Find the memory used by all states (expanded & real).

Returns
the total amount of memory that would be used by getting the arrays for all states.

Definition at line 1469 of file array_store.c.

References LISTBASE_FOREACH, state, and BArrayStore::states.

Referenced by BLI_array_store_at_size_calc_memory_usage(), and TEST().

◆ BLI_array_store_clear()

void BLI_array_store_clear ( BArrayStore bs)

◆ BLI_array_store_create()

BArrayStore* BLI_array_store_create ( unsigned int  stride,
unsigned int  chunk_count 
)

Create a new array store, which can store any number of arrays as long as their stride matches.

Parameters
stridesizeof() each element,
Note
while a stride of 1 will always work, its less efficient since duplicate chunks of memory will be searched at positions unaligned with the array data.
Parameters
chunk_countNumber of elements to split each chunk into.
  • A small value increases the ability to de-duplicate chunks, but adds overhead by increasing the number of chunks to look up when searching for duplicates, as well as some overhead constructing the original array again, with more calls to memcpy.
  • Larger values reduce the book keeping overhead, but increase the chance a small, isolated change will cause a larger amount of data to be duplicated.
Returns
A new array store, to be freed with BLI_array_store_destroy.

Definition at line 1388 of file array_store.c.

References BArrayInfo::accum_read_ahead_bytes, BArrayInfo::accum_read_ahead_len, BArrayInfo::accum_steps, BCHUNK_HASH_TABLE_ACCUMULATE_STEPS, BCHUNK_SIZE_MAX_MUL, BCHUNK_SIZE_MIN_DIV, BLI_MEMPOOL_ALLOW_ITER, BLI_mempool_create(), BLI_MEMPOOL_NOP, BArrayMemory::chunk, BArrayInfo::chunk_byte_size, BArrayInfo::chunk_byte_size_max, BArrayInfo::chunk_byte_size_min, BArrayMemory::chunk_list, BArrayMemory::chunk_ref, BArrayInfo::chunk_stride, BArrayStore::info, MAX2, MEM_callocN, BArrayStore::memory, and stride.

Referenced by BLI_array_store_at_size_ensure(), random_chunk_mutate_helper(), TEST(), testbuffer_run_tests_simple(), and text_undosys_step_encode_to_state().

◆ BLI_array_store_destroy()

void BLI_array_store_destroy ( BArrayStore bs)

◆ BLI_array_store_is_valid()

bool BLI_array_store_is_valid ( BArrayStore bs)

◆ BLI_array_store_state_add()

BArrayState* BLI_array_store_state_add ( BArrayStore bs,
const void data,
size_t  data_len,
const BArrayState state_reference 
)
Parameters
dataData used to create
state_referenceThe state to use as a reference when adding the new state, typically this is the previous state, however it can be any previously created state from this bs.
Returns
The new state, which is used by the caller as a handle to get back the contents of data. This may be removed using BLI_array_store_state_remove, otherwise it will be removed with BLI_array_store_destroy.

Definition at line 1497 of file array_store.c.

References bchunk_list_fill_from_array(), bchunk_list_from_data_merge(), bchunk_list_new(), BLI_addtail(), BLI_array_store_state_data_get_alloc(), BLI_assert, BLI_findindex(), BArrayState::chunk_list, BArrayInfo::chunk_stride, data, BArrayStore::info, MEM_callocN, MEM_freeN, BArrayStore::memory, state, BArrayStore::states, and BChunkList::users.

Referenced by TEST(), testbuffer_list_store_populate(), text_state_encode(), um_arraystore_cd_compact(), and um_arraystore_compact_ex().

◆ BLI_array_store_state_data_get()

void BLI_array_store_state_data_get ( BArrayState state,
void data 
)

Fill in existing allocated memory with the contents of state.

Definition at line 1562 of file array_store.c.

References BLI_assert, BTableRef::cref, BChunk::data, data, BChunk::data_len, BChunkRef::link, LISTBASE_FOREACH, state, and BChunk::users.

Referenced by BLI_array_store_state_data_get_alloc().

◆ BLI_array_store_state_data_get_alloc()

void* BLI_array_store_state_data_get_alloc ( BArrayState state,
size_t *  r_data_len 
)

◆ BLI_array_store_state_remove()

void BLI_array_store_state_remove ( BArrayStore bs,
BArrayState state 
)

Remove a state and free any unused BChunk data.

The states can be freed in any order.

Definition at line 1545 of file array_store.c.

References bchunk_list_decref(), BLI_assert, BLI_findindex(), BLI_remlink(), MEM_freeN, BArrayStore::memory, state, and BArrayStore::states.

Referenced by TEST(), testbuffer_list_store_clear(), text_undosys_step_free(), um_arraystore_cd_free(), and um_arraystore_free().

◆ BLI_array_store_state_size_get()

size_t BLI_array_store_state_size_get ( BArrayState state)
Returns
the expanded size of the array, use this to know how much memory to allocate BLI_array_store_state_data_get's argument.

Definition at line 1557 of file array_store.c.

References state.

Referenced by TEST().