Blender V4.3
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 (const BArrayState *state, void *data)
 
void * BLI_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 16 of file BLI_array_store.h.

◆ BArrayStore

typedef struct BArrayStore BArrayStore

Definition at line 17 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 1599 of file array_store.cc.

References LISTBASE_FOREACH, state, and BArrayStore::states.

Referenced by BLI_array_store_at_size_calc_memory_usage(), TEST(), 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 1494 of file array_store.cc.

References BArrayInfo::accum_read_ahead_bytes, BArrayInfo::accum_read_ahead_len, BArrayInfo::accum_steps, BCHUNK_HASH_TABLE_ACCUMULATE_STEPS_16BITS, BCHUNK_HASH_TABLE_ACCUMULATE_STEPS_32BITS, BCHUNK_HASH_TABLE_ACCUMULATE_STEPS_8BITS, BCHUNK_HASH_TABLE_ACCUMULATE_STEPS_DEFAULT, BCHUNK_SIZE_MAX_MUL, BCHUNK_SIZE_MIN_DIV, BLI_assert, 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, BArrayStore::memory, and UNLIKELY.

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

◆ BLI_array_store_destroy()

◆ BLI_array_store_is_valid()

◆ 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 1627 of file array_store.cc.

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, BArrayStore::info, MEM_freeN(), BArrayStore::memory, state, BArrayStore::states, and BChunkList::users.

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

◆ BLI_array_store_state_data_get()

void BLI_array_store_state_data_get ( const BArrayState * state,
void * data )

Fill in existing allocated memory with the contents of state.

Definition at line 1692 of file array_store.cc.

References BLI_assert, BChunk::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 )

◆ 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 1687 of file array_store.cc.

References state.

Referenced by TEST().