By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,305 Members | 1,843 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,305 IT Pros & Developers. It's quick & easy.

How to create a file in memory ?

P: n/a
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
Jul 22 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Lokicer" <lo*****@163.com> wrote...
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.


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

Victor
Jul 22 '05 #2

P: n/a

"Lokicer" <lo*****@163.com> wrote in message news:cg***********@mail.cn99.com...
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.

Try a Microsoft newsgroup or read the documentation of "CreateFile" in
the MSDN documentations.
Jul 22 '05 #3

P: n/a
"Lokicer" <lo*****@163.com> wrote in message news:<cg***********@mail.cn99.com>...
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.


Sounds a lot like a stringstream.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 22 '05 #4

P: n/a

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:swJVc.49191$mD.15134@attbi_s02...
"Lokicer" <lo*****@163.com> wrote...
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.


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


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
Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.