VLink  2.3.0
A high-performance communication middleware
fast_buffer.h 文件参考

Platform-independent buffer with a Header and a pointer-free wire envelope. 更多...

#include <cstddef>
#include <cstdint>
#include "../base/bytes.h"
#include "./header.h"
fast_buffer.h 的引用(Include)关系图:
此图展示该文件直接或间接的被哪些文件引用了:

浏览源代码.

命名空间

 
 

详细描述

Platform-independent buffer with a Header and a pointer-free wire envelope.

FastBuffer pairs sequencing metadata with a reference to CPU, device or other provider-managed storage. The first construction obtains the singleton FastBufferManager; VLINK_FASTBUFFER_PLUGIN selects a provider, while an unset or empty variable selects ordinary CPU memory.

Operation Payload behavior Ownership
create() Allocates in the selected domain Owns one provider reference
Copy / deep_copy() Copies through the provider Owns independent storage
shallow_copy() No payload copy Retains the same allocation
Move / move_copy() No payload copy Transfers the reference
Shared deserialization Imports a sharing descriptor Owns one import reference
Host deserialization Copies bytes into provider storage Owns independent storage
Memory access
+----------------+
| Header |
| local address -+----> CPU / GPU / DMA / virtual storage
| core ref | |
+----------------+ |
| |
+-- map()/unmap() <--- host-accessible mapping
|
+-- copy_to_host() ---> ordinary CPU Bytes
Holds a local memory address and an owned provider reference.
Definition: fast_buffer.h:138
40-byte timestamp / sequencing metadata prefix shared by all zero-copy containers.
address() is an opaque local address, not a CPU pointer. Use map() only when supported and pair it with unmap(); device-only allocations require explicit host transfer. Copies and synchronization use the provider.
Memory layout
Offset Size Field (64-bit targets)
------ ---- ----------------------------------
0 40 Header header
40 32 Buffer buffer_
72 8 MetadataBuffer* metadata_
80 8 uint64_t reserved_buf_
88 8 uint64_t reserved_buf2_
------ ---- ----------------------------------
Total 96 bytes (alignas 8)
Wire format
The fixed wire header is serialized independently of the local Metadata view and C++ object. Pointers, ownership references and process-local device indices never travel in the envelope. Byte order follows the other zero-copy types.
Metadata offset Size Field
--------------- ---- ----------------------------------
0 40 Header header
40 8 uint64_t size
48 8 uint64_t protocol
56 1 Storage storage
57 1 MemoryType memory_type
58 6 uint8_t reserved1[6] (zero)
64 8 uint64_t metadata_size
72 16 uint64_t reserved[2]
--------------- ---- ----------------------------------
Total 88 bytes (alignas 8)
[ magic_begin (4) | version (4) | wire header (88) | metadata (M) | payload (N) | magic_end (4) ]
Wire storage Payload Availability
Shared Control block name and generation Compatible provider and live source
Host Complete CPU-readable bytes No sharing descriptor required

operator>> uses a sharing descriptor when supported, otherwise host bytes. A shared descriptor names the allocation and its generation; importing after the owner reused (FastBufferPool) or retired the allocation fails as expired, and the message is dropped. MessageParser reads and prints metadata without importing the allocation. Variable-length metadata is ordinary CPU storage, separate from the provider payload. set_metadata() copies input bytes or adopts an owned rvalue; shallow_copy() retains that metadata allocation without copying its contents.

Example
vlink::zerocopy::FastBuffer buffer;
const auto input = vlink::Bytes::create(1024);
if (buffer.create(input.size()) && buffer.copy_from_host(input)) {
if (buffer >> wire) {
vlink::zerocopy::FastBuffer received;
if (received << wire) {
vlink::Bytes output;
const bool copied = received.copy_to_host(output);
}
}
}
Publishers recycle allocations through vlink::zerocopy::FastBufferPool; the sharing contract is defined by vlink::FastBufferPluginInterface and vlink::FastBufferManager.