FBB::MemoryStream(3bobcat)
πΈ FBB::MemoryStream β I/O operations on memory segments πΈ
okay bestie, welcome to FBB::MemoryStream(3bobcat), part 1 of 2 π this is the part where we meet the class, the constructors, and every single member function. no skipping, no summarizing, we're doing the whole thing π«Ά
β¨ NAME β¨
FBB::MemoryStream β I/O operations on memory segments. periodt π
β¨ SYNOPSIS β¨
#include <bobcat/memorystream>
Linking option: -lbobcat
yes queen, one include and one link flag, that's the whole vibe π
β¨ DESCRIPTION β¨
so basically this class is giving both std::istream and std::ostream energy at the same time, but it does all its reading and writing on memory segments (like, cf. shmget(2), iykyk) β¨
and here's the tea you need to internalize: just like std::fstream objects, FBB::MemoryStream objects do not keep separate offsets for reading and writing. nope. the seek members always refer to the one single offset that the FBB::MemoryBridge object maintains β and that's the object your MemoryStream interfaces with, indirectly. one offset, one truth, no cap π
β¨ NAMESPACE β¨
FBB
every single constructor, member, operator and manipulator mentioned in this man page lives in the namespace FBB. all of them. every last one π
β¨ INHERITS FROM β¨
FBB::MemoryBuf(private inheritance) πstd::iostreamπ
β¨ CONSTRUCTORS β¨
MemoryStream()β the default constructor. it defines a stubMemoryStreamobject that cannot immediately be used to access memory segments. to actually use it you have to call its memberopenfirst. it's like a blank canvas bestie, beautiful but currently useless πΈMemoryStream(std::string const &bufSize, [bool erase = false,] std::ios::openmode openMode = std::ios::in | std::ios::out, size_t access = 0600)β constructs aMemoryStreamobject that inherits all the facilities of thestd::iostreamclass. its default capacity is specified bybufSize(go peek at the BUFSIZE section for the whole story), using memory segment(s) that contain the stream's bytes.
the access rights of the data stored in MemoryStream objects are defined by the access parameter, which gets interpreted as an octal value, using the same specifications that chmod(1) uses π
the erase parameter is the "what happens when you leave" setting for the memory segments once the MemoryStream object goes out of scope. when it's omitted or specified as false, the allocated memory segments are not erased from memory when the object goes out of scope β and yes, that means they can be reaccessed until the computer is rebooted, using the memory object's ID (see the next constructor π). when it's specified as true, the memory segments are erased from memory when the object goes out of scope. choose wisely bestie π
if construction fails, an FBB::Exception is thrown. π
MemoryStream(int id, [bool erase = false,] std::ios::openmode openMode = std::ios::in | std::ios::out)β constructs aMemoryStreamthat connects to the memory segments created by the previous constructor, using the memory segment's ID defined by that constructor. it's giving "reunited and it feels so good" π¦
the erase parameter is used exactly the way it's used by the previous constructor. same rules, same drama.
specifying the ios::trunc flag (or a comparable flag β like, merely ios::out counts) immediately clears the current content of the memory segments. gone. poof. π
an FBB::Exception is thrown if construction fails (e.g., when no memory segment having ID id exists). π
β οΈ the move/copy constructors and assignment operators are not available. not on the menu, don't ask π«
β¨ BUFSIZE β¨
the bufSize parameter β required by the second MemoryStream constructor and by the open member (scroll down for that one) β specifies the default number of shared memory blocks and their sizes π
the size of the memory blocks is specified as k, M or G, indicating block sizes in kilo-, Mega- and GigaBytes. before those letters you specify the default number of blocks. e.g., "100M" β¨
internally the number of kiloBytes gets converted to pages, using the system's page size, which is commonly equal to 4 kB β so when you specify "5k", the stream prepares for two shared data segments, each having a capacity of 4 kB π
the number of MegaBytes is used as specified, and when you specify GB the data segments are .5 GB.
the number of shared data segments is automatically enlarged when the current capacity is exceeded, and the potentially available data segments are initially not allocated: they get allocated once information is written into their areas. lazy allocation, honestly iconic π§
β¨ MEMBER FUNCTIONS β¨
all members of std::iostream are available. yes, all of them, we're spoiled π«Ά
void exceptions(std::ios::iostate flag)β after you call this member, exceptions thrown while processing aMemoryStreamleave theMemoryStreamobject, setting the stream's state toflag. such exceptions are caught as usual, while the object'siostateis set toflag, which lets you distinguish internally generated exceptions from other exceptions π commonly the argumentstd::ios::badbitis used.int id() constβ the ID of the memory segments is returned. that's it, that's the whole function πvoid info(std::ostream &out)β information about the object'sMemoryBufis inserted intoout: the IDs of the memory data blocks, their sizes, the current maximum number of memory data blocks, the number of bytes that can be read from the memory segments, and its actual storage capacity. it's the full gossip session πΈstd::streamsize maxEnd() constβ when using aMemoryStreamobject, the offset just beyond the current maximum offset is returned. e.g., if aMemoryStreamobject is configured with 5 data blocks of 1 MB each, thenmaxEndreturns5 * 1024 * 1024. when the object extends its number of data blocks,maxEndreturns the corresponding new value π₯void open(char const *bufSize, [bool erase = false,] std::ios::openmode openMode = std::ios::in | std::ios::out, size_t access = 0600)β this member can be used to activate aMemoryStreamobject that was initially created by its default constructor. it expects the same argument as the second constructor. a matchingclosemember does not exist and is not required π
if opening fails, an FBB::Exception is thrown. π
void open(int id, [bool erase = false,] std::ios::openmode openMode = std::ios::in | std::ios::out, size_t access = 0600)β this member can be used to activate aMemoryStreamobject that was initially created by its default constructor, specifying the ID of a previously constructedMemoryStreamobject. it expects the same argument as the third constructor. a matchingclosemember does not exist and is not required β¨
if opening fails, an FBB::Exception is thrown. π
void setErase(bool erase)β this member is used to change the erase setting of aMemoryStreamobject. it can be used by, e.g., forking programs where the program constructs aMemoryStreamobject specifyingerase == false, but whose memory segments should be erased when the parent process ends and not also when the child process ends. this is accomplished by callingsetErase(true)in the parent process. family drama, resolved πvoid truncate(std::streamsize size)β this member is used to reduce or enlarge the available memory size of aMemoryStreamtosize. if it's reduced, then the memory segments' data bytes fromsizeto its original size are set to0. newly allocated memory segments are always initialized to0byte values. fresh start energy π
π that's the first half bestie, part 2 is coming with the example, the files, the SEE ALSO and the bugs section β so don't go anywhere, we're not done yet β¨
okay so last lil' drop of links before we wrap this whole thing up π β here's where the entire Bobcat situation lives:
- https://fbb-git.gitlab.io/bobcat/: the gitlab project page, that's literally the spot bestie;
- Debian Bobcat project files:
libbobcat6β the debian package holding the shared library, the changelog and the copyright note;libbobcat-devβ the debian package holding the static library, the headers, the manual pages, and all the developer info;
π± BOBCAT π±
fun fact, no cap: Bobcat is an acronym of `Brokkenβs Own Base Classes And Templatesβ.
ngl that is such a clean acronym and I'm obsessed π«Ά
Β©οΈ COPYRIGHT Β©οΈ
This is free software, distributed under the terms of the GNU General Public License (GPL). so yes bestie, it's free, it's GPL, go be great with it π
π«Ά AUTHOR π«Ά
Frank B. Brokken (f.b.brokken@rug.nl).
and that's the whole page, bestie, we made it to the end πβ¨ this one rides along with libbobcat-dev_6.15.01, and the timeline stamped on it runs all the way from 2005 to 2026 β a two-decade glow-up, which is honestly iconic behavior ππ go stream your memory like the main character you are, periodt π¦πΈ
π¦ where this page comes from
- ubuntu stonking: libbobcat-dev 6.15.01-1 Β· GPL-3.0-or-later WITH OpenSSL exception
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms