FastMM documentation
FastMM C++ API 0.14.0
Public headers, tier 1 and tier 2
Loading...
Searching...
No Matches
state_codec.hpp File Reference

StateWriter and StateReader: the bytes of a strategy's state() and restore() without allocating or throwing. More...

#include <cstddef>
#include <cstdint>
#include <cstring>
#include <span>
#include <string_view>
#include <type_traits>

Go to the source code of this file.

Classes

class  fastmm::StateWriter
 
class  fastmm::StateReader
 

Namespaces

namespace  fastmm
 

Detailed Description

StateWriter and StateReader: the bytes of a strategy's state() and restore() without allocating or throwing.

The writer fills a buffer the strategy owns and sizes once, so a checkpoint costs a copy of the state and nothing else; a write that does not fit fails the writer instead of growing it. Values are copied in the machine's own layout: trivially copyable types only, read back in the order they were written. The strategy's state_version (strategies/hooks.hpp) names the layout.

StateWriter w(buf_); // std::span<std::byte> sized in on_start w.put(avg_); w.put_array(std::span<const Slot>(slots_.data(), n_)); return w.view(); // empty when the buffer was too small

StateReader r(bytes); return r.get(avg_) && r.get_array(slots_.data(), slots_.size(), n_) && r.done();