Functions | |
| template<typename Converter , class Range , std::enable_if_t< std::is_same_v< Range, Particles >||std::is_same_v< Range, ParticleList >, bool > = true> | |
| void | write_in_chunk_impl (const Range &particles, const OutputFormatter< Converter > &formatter, std::function< void(const typename Converter::type &)> write, std::size_t max_buffer_bytes=1 '000 '000 '000) |
| Writes particle data in multiple chunks if the total buffer size exceeds a predefined maximum. More... | |
| void smash::details::write_in_chunk_impl | ( | const Range & | particles, |
| const OutputFormatter< Converter > & | formatter, | ||
| std::function< void(const typename Converter::type &)> | write, | ||
| std::size_t | max_buffer_bytes = 1'000'000'000 |
||
| ) |
Writes particle data in multiple chunks if the total buffer size exceeds a predefined maximum.
This method avoids creating a single excessively large binary buffer when writing many particles at once. Instead, it splits the write into several smaller chunks. This can prevent excessive memory usage and improve stability on systems or filesystems that may have trouble with very large write calls.
The maximum buffer size is currently set to 1 GB (10^9 bytes), but this can be adapted in the future if needed. If the total data size of the particle block is below this threshold, the method simply delegates to the write function which should perform a single write call.
Otherwise, the data is accumulated particle by particle until the buffer reaches the threshold. The buffer is then given to the write function which should flush to disk.
| Converter | Converter used by OutputFormatter to produce the buffer type (must define Converter::type). |
| Range | Container type — enforced to be either Particles or ParticleList. |
| [in] | particles | Container of particles whose particle_line representation is to be written. |
| [in] | formatter | Formatter responsible for converting particles into the corresponding Converter::type buffer representation. |
| [in] | write | Callable that receives each filled buffer chunk and performs the actual write to the underlying output (e.g. file). |
| [in] | max_buffer_bytes | Maximum buffer size in bytes before the accumulated data is flushed via write (default: 1'000'000'000). |
| std::runtime_error | If the estimated size of a single particle line exceeds half of max_buffer_bytes. In that case, only one particle would fit per chunk, which defeats the purpose of chunked writing, and the caller must increase max_buffer_bytes accordingly. |
Definition at line 695 of file outputformatter.h.