VLink  2.3.0
A high-performance communication middleware
fast_buffer_pool.h File Reference

Fixed-depth publisher pool that recycles FastBuffer allocations by generation. More...

#include <cstddef>
#include <vector>
#include "./fast_buffer.h"
Include dependency graph for fast_buffer_pool.h:

Go to the source code of this file.

Classes

class  vlink::zerocopy::FastBufferPool
 Owns a fixed set of equally sized allocations and recycles them in round-robin order. More...
 

Namespaces

 
 

Detailed Description

Fixed-depth publisher pool that recycles FastBuffer allocations by generation.

A publisher of shared descriptors must neither overwrite an allocation that importers still read nor wait for them. FastBufferPool owns depth allocations of one size and hands out the next one whose readers have all released it. The manager increments that allocation's generation first, so descriptors published earlier for it fail to import as expired instead of observing overwritten bytes. Dead reader processes are purged by identity, so a crashed subscriber never pins a slot.

Call Effect
create(size, depth) Allocates depth uninitialised buffers through the provider
acquire(buffer) Clears buffer, then retains the next reusable slot
clear() Releases the slots; retained buffers keep theirs alive
Publish cycle
vlink::zerocopy::FastBuffer frame;
if (pool.create(frame_size, 4)) {
while (running) {
if (pool.acquire(frame)) {
fill(frame); // map()/unmap() or device work
pub.publish(frame); // shared descriptor when the provider supports it
} // otherwise every slot is still being read: skip this frame
} // dropping frame returns its slot without waiting
}
Choose depth larger than the deepest subscriber queue plus the frames a subscriber retains; slower subscribers then drop expired frames rather than stalling the publisher. One thread drives a pool.