Getting a file descriptor or a file number) for an fstream (Was: Accessing the underlying file descriptor in fstream)

Theodore Papadopoulo Theodore.Papadopoulo@sophia.inria.fr
Wed Feb 14 09:33:00 GMT 2001


gdr@codesourcery.com said:
> If your need is to have a C++ ISOstream operating over a FILE* C or a
> int, then it should be not be hard to implement your own class
> (derived from standard stream classes) to implement your policy.
> Passing them back to the rest of the standard algorithms should be
> trouble-less.  

No my problem is the opposite. I have a stream and at some point I 
want to memory map part of the file that has been open throught the 
stream and I do not have the file name any longer. Typically an image
with an ascii header that I want to parse with streams, but the binary
data which are loaded using the read method right can sometimes be memory
mapped. On big image sequences, readding everything into memory is painfully
slow all the more that often not all the data is used. Memory 
mapping is a good alternative in such a case.
But, this is just an example...

spencer@infointeractive.com said:
>    // Swap out the old one with the new one and toss the oldone
>    delete m_realFile.rdbuf(fb);
> I wrote my own subclass of filebuf that tees the output to syslog.  I
> just do this line (above) to swap in the new filebuf.  The C++
> IOStreams library is extensible, and it's not that hard to extend it.
> I can recommend Standard C++ IOStreams and Locales by Langer and
> Kreft. 

This is probably possible. My guess is just that many people will want 
to do something similar (and I suppose that's why it was available in the old 
v2 library). Having a simple hook that provides FILE* is the simplest thing
to accomodate this need for everyone at a single place, without 
requiring everyone to recode something of his own.

But that's just my 2c...

	Theo.


--------------------------------------------------------------------
Theodore Papadopoulo
Email: Theodore.Papadopoulo@sophia.inria.fr Tel: (33) 04 92 38 76 01
 --------------------------------------------------------------------


-- 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: Exmh version 2.2 06/23/2000

iD8DBQE6isF0IzTj8qrxOU4RAiUrAJ9PNN/G/FbkubTo/X+4D1sG/TS4WQCfZmMh
MCJal3A6JCRS568nB194Ijs=
=76Vd
-----END PGP SIGNATURE-----


More information about the Libstdc++ mailing list