Connecting Tech Pros Worldwide Forums | Help | Site Map

How to create a file in memory ?

Lokicer
Guest
 
Posts: n/a
#1: Jul 22 '05
Hi all,

i want to create a file in memory and access the memory block like a
file(i/o function) in windows 2000. Any hlep are appreciated.

Regards,
Zheng



Victor Bazarov
Guest
 
Posts: n/a
#2: Jul 22 '05

re: How to create a file in memory ?


"Lokicer" <lokicer@163.com> wrote...[color=blue]
> i want to create a file in memory and access the memory block like a
> file(i/o function) in windows 2000. Any hlep are appreciated.[/color]

The simplest way I know is to use std::stringstream.

Victor


Ron Natalie
Guest
 
Posts: n/a
#3: Jul 22 '05

re: How to create a file in memory ?



"Lokicer" <lokicer@163.com> wrote in message news:cg7ncr$2itb$1@mail.cn99.com...[color=blue]
> Hi all,
>
> i want to create a file in memory and access the memory block like a
> file(i/o function) in windows 2000. Any hlep are appreciated.
>[/color]
Try a Microsoft newsgroup or read the documentation of "CreateFile" in
the MSDN documentations.
Jerry Coffin
Guest
 
Posts: n/a
#4: Jul 22 '05

re: How to create a file in memory ?


"Lokicer" <lokicer@163.com> wrote in message news:<cg7ncr$2itb$1@mail.cn99.com>...[color=blue]
> Hi all,
>
> i want to create a file in memory and access the memory block like a
> file(i/o function) in windows 2000. Any hlep are appreciated.[/color]

Sounds a lot like a stringstream.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jonathan Turkanis
Guest
 
Posts: n/a
#5: Jul 22 '05

re: How to create a file in memory ?



"Victor Bazarov" <v.Abazarov@comAcast.net> wrote in message
news:swJVc.49191$mD.15134@attbi_s02...[color=blue]
> "Lokicer" <lokicer@163.com> wrote...[color=green]
> > i want to create a file in memory and access the memory block[/color][/color]
like a[color=blue][color=green]
> > file(i/o function) in windows 2000. Any hlep are appreciated.[/color]
>
> The simplest way I know is to use std::stringstream.[/color]

stringstream is useful a lot of the time, but it has the following
limitations (both reasonable, in context):

1. You can't specify that the stream access a pre-existing block of
memory,
2. When you're done performing i/o you can't get direct access to the
underlying memory -- you have to settle for a copy.

A library up for review at boost (by Darlye Walker) offers a
collection of streams and stream buffers for accessing arrays
directly, with this usage:

char buf[1000];
boost::io::pointerstream ps(buf, buf + 1000);

Here buf need not be on the stack -- it could just as well be
dynamically allocated. Of course, unlike with a std::stringstream, the
user has to be careful not to write past the end of the array.

I've submitted a slightly more general iostreams libray which allows
the creation of a pointerstream as follows:

typedef boost::io::stream_facade<array_resource>
pointerstream;
char buf[1000];
pointerstream ps(buf, buf + 1000);

You can also access mmap'd files as follows:

typedef boost::io::stream_facade<mapped_file_resource>
mapped_fstream;
mapped_fstream ms("hello.txt");

Docs are here:

more_io (Daryle Walker) http://tinyurl.com/5d9xt
iostreams (Jonathan Turkanis) http://tinyurl.com/4zfmt

Jonathan


Closed Thread