VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
fast_stream.h 文件参考

A high-performance std::ostream backed by a resizable std::string buffer. 更多...

#include <ostream>
#include <string>
#include <string_view>
#include "./macros.h"
fast_stream.h 的引用(Include)关系图:
此图展示该文件被哪些文件直接或间接地引用了:

浏览该文件的源代码.

 High-performance std::ostream with an embedded resizable string buffer. 更多...

命名空间

详细描述

A high-performance std::ostream backed by a resizable std::string buffer.

FastStream is a specialised output stream designed for zero-copy, low-latency log formatting inside the VLink Logger. It inherits from std::ostream, so any standard stream manipulator or operator<< overload works transparently.

Key design points:

  • Backed by an internal StringBuf that stores data in a std::string (avoids heap fragmentation for short messages via a pre-allocated capacity).
  • take_view() returns a std::string_view into the internal buffer, enabling zero-copy hand-off to the logger sink without an extra copy.
  • write_raw() bypasses std::ostream formatting and writes bytes directly into the underlying buffer, suitable for pre-formatted C-strings.
  • Default capacity is 256 bytes; the buffer grows automatically in 8 KiB increments up to any size. shrink_to_fit() can reclaim excess memory after an unusually long message.
注解
  • FastStream is not thread-safe. Each thread should own its own instance, which is the pattern used by the Logger (thread_local FastStream).
  • Calling take_view() invalidates any previously taken view after the next write or explicit reset(). Do not hold views across multiple log calls.
Example
stream << "sensor_id=" << 42 << " value=" << 3.14;
std::string_view view = stream.take_view(); // view valid until next write
write_to_sink(view);