[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C++ iostreams

I Found a (for my application) a even better way.
Using mmap to create a char* buffer from a file 
and than using mem_buffer. Still working on it but 
it should work. And hopefully should be very fast :-)

- Erwin

Jose Orlando Pereira wrote:
> Erwin Rol wrote:
> > I am new to XTL and am wondering how to use it with
> > C++ streams. In the documentation there is something about
> > c FILE* input/output but nothing about C++ streams (at least
> > no examples). I also didn't got the cfile_buffer example to work
> > thats in the docu.
> You're correct. Mentions to externalization to FILEs and streams
> are currently just wishful thinking. mem_buffers are enough for
> me, so I never got around doing the others.
> However, it should be fairly easy to implement them. Take a look
> at mem_buffer in objio.h. read() and write() have the expected
> semantics and should translate into fread()/fwrite or whatever
> is needed.
> In addition, require() and flush() are used for atomic types with
> size less or equal to sizeof(longlong) and need to be implemented.
> For instance, as:
>  char buffer[sizeof(longlong)];
>  int n=0;
>  void* require(int size) {flush();n=size;return buffer;}
>  void flush() {write(buffer, n);n=0;}
> for a write-only stream and:
>  char buffer[sizeof(longlong)];
>  void* require(int size) {read(buffer, size);return buffer;}
>  void flush() {}
> for a read-only stream.
> For buffered streams (e.g. FILEs or iostreams), this should be ok.
> For unbuffered streams, some coalescing should be done by require(),
> making it more complex but vastly faster.
> BTW, unrequire() is required :-) only for text format, so it might be
> safely ignored.
> --
> Jose Orlando Pereira
> * mailto:jop@di.uminho.pt * http://gsd.di.uminho.pt/~jop *