FBB::MemoryStream(3bobcat)

I/O on memory segments
(libbobcat-dev_6.12.01)

2005-2026

NAME

FBB::MemoryStream - I/O operations on memory segments

SYNOPSIS

#include <bobcat/memorystream>
Linking option: -lbobcat

DESCRIPTION

This class combines the features of the std::istream and std::ostream classes, operating on memory segments (cf. shmget(2)).

As with std::fstream objects, FBB::MemoryStream objects do not keep separate offsets for reading and writing: the seek-members always refer to the (single) offset maintained by the FBB::MemoryBridge object to which the MemoryStream object (indirectly) interfaces.

NAMESPACE

FBB
All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB.

INHERITS FROM

FBB::MemoryBuf (private inheritance),
std::iostream,

CONSTRUCTORS

The move/copy constructors and assignment operators are not available.

BUFSIZE

The bufSize parameter required by the second MemoryStream constructor and the open member (see below) specifies the default number nummber of shared memory 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 the default number of blocks is specified. E.g., "100M". Internally the number of kiloBytes is converted to `pages', using the system's page size, which is commonly equal to 4 kB (so when specifying "5k" then 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 specifying GB the data segments are .5 GB.

The number of shared data segments is aotomatically enlarged when the current capacity is exceeded, and the potentially available data segments are initially not allocated: they're allocated once information is written into their areas.

MEMBER FUNCTIONS

All members of std::iostream are available.

EXAMPLE

#include <iostream>
#include <string>
#include <ostream>
#include <istream>

#include <bobcat/exception>
#include <bobcat/memorystream>

using namespace std;
using namespace FBB;

int main(int argc, char **argv)
{
    MemoryStream ms;

    char ch = 'h';
    string cmd;

    while (true)
    {
        ios::off_type offset;

        switch (ch)
        {
            case 'h':
                cout <<
                    "\n"
                    " b     open a MemoryStream for 10k\n"
                    " h     this info\n"
                    " i     show info about the memory stream\n"
                    " o     show the current absolute offset\n"
                    " q     quit\n"
                    " s <x> seek (abs) offset x\n"
                    " x     extract the next line from the current offset\n"
                    " <     insert lines (until empty) at the current "
                                                            "offset\n"
                    " >     extract lines (until EOF) from the current "
                                                            "offset\n";
            break;

            case 'b':
                ms.open("10k", true);
            [[fallthrough]];

            case 'i':
                ms.info(cout);
            break;

            case 'o':
                cout << ms.seekg(0, ios::cur).tellg() << '\n';
            break;

            case 'q':
            return 0;

            case 's':
            {
                size_t offset;
                cin >> offset;
                cout << "tellg: " << ms.seekg(offset).tellg() << '\n';
            }
            break;

            case 'x':
            {
                string line;
                if (getline(ms, line))
                    cout << line << '\n';
                else
                {
                    cout << "No lines available\n";
                    ms.clear();
                }
            }
            break;

            case '<':
            {
                cin.ignore(100, '\n');
                while (true)
                {
                    string line;
                    getline(cin, line);
                    if (line.empty())
                        break;
                    ms << line << endl;
                }
            }
            break;

            case '>':
            {
                string line;
                while (getline(ms, line))
                    cout << line << '\n';
                ms.clear();
                ms.seekg(0, ios::end);
            }
            break;
            default:
                cout << "request `" << ch << "' not implemented\n";
            break;
        }

        cout << "? ";
        cin >> ch;
    }
}

FILES

bobcat/memorystream - defines the class interface

SEE ALSO

bobcat(7), chmod(1), memorybuf(3bobcat), memoryreadme(7bobcat), shmget(2)

BUGS

None reported

BOBCAT PROJECT FILES

Debian Bobcat project files:

BOBCAT

Bobcat is an acronym of `Brokken's Own Base Classes And Templates'.

COPYRIGHT

This is free software, distributed under the terms of the GNU General Public License (GPL).

AUTHOR

Frank B. Brokken (f.b.brokken@rug.nl).