#include <GGUI/Public/Snapshot.h>
template<typename T, uint32_t PerChunk>
SharedChunks class
SharedChunks: an indexed array in ref-counted chunks shared between consecutive snapshots.
The snapshot being written shares the previous one's chunks (ShareFrom) and copies a chunk only when it writes to it. Only the writer thread shares, edits, or releases; any thread reads.
Public static functions
- static auto ChunkBytes() -> size_t
- The size of one chunk.
Constructors, destructors, conversion operators
- SharedChunks() defaulted
- Empty.
- ~SharedChunks()
- SharedChunks(const SharedChunks& other)
- A copy of every chunk, shared with nothing.
Public functions
- auto operator=(const SharedChunks& other) -> SharedChunks&
- The same, assigned.
- auto Find(uint32_t index) const -> const T*
- The item at
index; null if its chunk was never written. - void Read(uint32_t first, uint32_t count, T* out) const
- Copy
countitems fromfirstintoout. Unwritten items are default-made. - auto Bytes() const -> size_t
- Memory held, counting shared chunks as its own.
- void Collect(std::vector<const void*>& out) const
- Its chunk pointers, for deduplicating memory counts across snapshots.
- void ShareFrom(const SharedChunks* other)
- Share
other'schunks (null: none). - void KeepOwn(bool bEmptied = false)
- Release every chunk that is shared and keep the unshared ones for reuse, either as they are or, with
bEmptied, reset. - auto Edit(uint32_t index) -> T&
- The item at
indexto write, its chunk made and unshared first if need be. - void Write(uint32_t first, const T* items, uint32_t count)
- Write
countitems fromfirst. - void Fill(uint32_t first, uint32_t count, const T& item)
- Write
itemtocountslots fromfirst.