FBB::SharedBuf(3bobcat)
π FBB::SharedBuf π β from the bobcat manuals, section 3
okay bestie sit DOWN because we're about to talk about the streambuf that talks to shared memory and it's genuinely so cool π«Ά
β¨ NAME β¨
FBB::SharedBuf β the streambuf that interfaces to shared memory. that's it, that's the whole job π
πΈ SYNOPSIS πΈ
#include <bobcat/sharedbuf>
Linking option: -lpthread -lbobcat
like, link it properly or it simply will not vibe with you. no cap.
π¦ DESCRIPTION π¦
so this class is a specialization of std::streambuf, and what that means is it lets stream classes do actual I/O on shared memory. we're talking std::istream, std::ostream, FBB::ISharedStream, FBB::OSharedStream and FBB::SharedStream β all of them, slaying together. and the way it works is that FBB::SharedBuf objects interface to FBB::SharedMemory objects. iconic behavior honestly.
π NAMESPACE π
FBB
every single constructor, member, operator and manipulator that gets mentioned in this man page lives in the namespace FBB. don't @ me.
π INHERITS FROM π
std::streambufFBB::SharedEnum__β and if you wanna know about that one, go readsharedmemory(3bobcat), it's all explained there π
β SIZEUNIT ENUMERATION β
the enum SizeUnit defines these symbolic constants, and they're your units of memory, bestie:
kB, representing 1024 (2**10) bytes of memory;MB, representing 1048576 (2**20) bytes of memory;GB, representing 1073741824 (2**30) bytes of memory
π CONSTRUCTORS π
SharedBuf()β the default constructor. this one makes a stubSharedBufobject that literally cannot be used to access shared memory right away. so before shared stream classes likeFBB::SharedStreamcan use it, you gotta call itssetMemorymember first. nosetMemory, no shared memory, periodt.SharedBuf(size_t maxSize, SizeUnit sizeUnit, std::ios::openmode openMode = std::ios::in | std::ios::out, size_t access = 0600)β this one creates a shared memory segment with a capacity of at leastmaxSize * sizeUnitbytes. by default the segment is opened for reading and writing. and here's the tea: unlike the open modes for file streams, creating a shared memory stream with open modesios::in | ios::outis totally OK. in this case the shared memory segment is created, and once info has been written to the shared memory it can be read again too. the shared memory's access rights come from theaccessparameter, which is interpreted as an octal value, using the well-known (chmod(1)) way of defining access rights for owner, group and others. if construction fails, anFBB::Exceptiongets thrown πSharedBuf(int id, std::ios::openmode openMode = std::ios::in | std::ios::out)β this one connects to a shared memory segment that has IDid. specifying theios::truncflag immediately clears the content of the shared memory, just so you know. anFBB::Exceptionis thrown if construction fails (e.g., no shared memory segment having IDidexists).
π¨ also copy and move constructors (and assignment operators) are not available. so don't try it, bestie, it's not giving what you think it's giving.
π MEMBER FUNCTIONS π
all members of std::streambuf and the enum values kB, MB, and GB defined by FBB::SharedEnum__ are available to you. yes, all of them. we're rich.
void clear()β the shared memory is first locked. next, all shared data segment are returned to the operating system, after which the shared memory segment is unlocked again. returning fromclear, theFBB::SharedMemoryobject is effectively re-initialized, withoffsetandnReadablereturning 0. fresh start, clean slate, main character energy β¨int id() constβ returns the ID of the shared memory segment. short, sweet, useful.void kill()β deletesFBB::SharedBuf's shared memory, and it does this without locking the shared memory. after returning fromkilltheFBB::SharedBufobject is unusable. like, gone. bye πvoid memInfo(std::ostream &out)β inserts info about theSharedMemoryobject into the provided ostream object. you get the IDs of the shared segments, their sizes, the maximum number of shared memory segments, the number of bytes that can be read from the shared memory, its actual storage capacity, etc. the inserted information is not terminated by a final newline character, so don't come for it about the newline.void remove()β the shared memory is locked, and thenFBB::SharedBuf's shared memory is deleted. theFBB::SharedBufobject is unusable after returning fromremove. same energy askillbut it locks first, okay? different vibes, both permanent.void setMemory(SharedMemory &&tmp)β the anonymous temporarySharedMemoryobject passed tosetMemorydefines the new shared memory segment that theFBB::SharedBufobject interfaces to. you can also call it to reuse aFBB::SharedBufobject again after callingkillorremove. it's giving resurrection π₯FBB::SharedMemory &sharedMemory()β returns a reference to theFBB::SharedMemoryobject that theFBB::SharedBufobject interfaces to.
π§ PROTECTED MEMBER FUNCTIONS π§
FBB::SharedCondition attachSharedCondition(std::ios::off_type offset, std::ios::seekdir origin)β returns anFBB::SharedCondition(3)object that interfaces to a shared condition variable located atoffset(relative toorigin) in theSharedMemoryobject that theSharedStreamBufobject interfaces to. anFBB::Exceptionis thrown if theFBB::SharedConditionobject could not be constructed πFBB::SharedCondition createSharedCondition()β returns anFBB::SharedCondition(3)object that interfaces to a newly created shared condition variable, created at the current offset of theSharedMemoryobject that theSharedStreamobject interfaces to (or at the first offset of the next physical shared memory data block, cf.sharedcondition(3bobcat)). anFBB::Exceptionis thrown if theFBB::SharedConditionobject could not be constructed.void setOpenMode(std::ios::openmode flag)β changes the streambuf's openmode to the settings defined byflag. this member gets used by, e.g.,SharedStream::open, to adaptFBB::SharedBuf's openmode to the flags that are passed toopen.FBB::SharedMemory &sharedMemory()β returns a reference to theFBB::SharedMemoryobject that theSharedBufobject interfaces to.
π EXAMPLE π
go look at the sharedstream(3bobcat) man page, bestie, it's all there for you π«Ά
πΈ FILES πΈ
bobcat/sharedbuf β defines the class interface
π SEE ALSO π
bobcat(7), chmod(1), isharedstream(3bobcat), osharedstream(3bobcat), sharedblock(3bobcat), sharedcondition(3bobcat), sharedmemory(3bobcat) sharedmutex(3bobcat), sharedpos(3bobcat), sharedreadme(7bobcat), sharedsegment(3bobcat), sharedstream(3bobcat)
π BUGS π
okay this one actually matters so listen up. by default, exceptions thrown from within a std::stream object get caught by the stream object itself, and it sets its ios::failbit flag. so if you want exceptions to actually leave a stream object, you gotta call its exceptions member, like this:
myStream.exceptions(ios::failbit | ios::badbit | ios::eofbit);
learn it, love it, because otherwise your exception is just... sitting in there. trapped. π
π₯ BOBCAT PROJECT FILES π₯
https://fbb-git.gitlab.io/bobcat/: gitlab project page;
Debian Bobcat project files:
libbobcat6: debian package containing the shared library, changelog and copyright note;libbobcat-dev: debian package containing the static library, headers, manual pages, and developer info;
π BOBCAT π
Bobcat is an acronym of `Brokken's Own Base Classes And Templates'. yes, really. iconic naming, honestly.
β COPYRIGHT β
this is free software, distributed under the terms of the GNU General Public License (GPL). free as in freedom, bestie π
π«Ά AUTHOR π«Ά
Frank B. Brokken (f.b.brokken@rug.nl).
aaaand that's the whole page!! π this was libbobcat-dev_6.07.01, dated 2005-2025, and it's your girl FBB::SharedBuf(3bobcat) signing off β go write some shared memory, you absolute legend πβ¨
π¦ where this page comes from
- debian trixie: libbobcat-dev 6.07.01-2 Β· GPL-3.0-or-later WITH OpenSSL exception
- ubuntu questing: libbobcat-dev 6.07.01-2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms