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

In-memory array output stream?

P: n/a
Hi,
My application needs to create in-memory arrays, the size of which is not
known, or very hard to calculate, in advance. I would like to stream the
data using the standard I/O class framework. The class should take care of
the underlying memory management. Now which class is most suitable for this?
(Assuming there is one.) Will std::ostrstream do the trick?

In Java I use java.io.ByteArrayOutputStream to create in-memory data.
Thanks
-Laurens
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Laurens wrote:
Hi,
My application needs to create in-memory arrays, the size of which is not
known, or very hard to calculate, in advance
On second reading, I assume you mean "in advance of the I/O I'm about to
tell you about."
I would like to stream the
data using the standard I/O class framework. The class should take care of
the underlying memory management. Now which class is most suitable for this?
(Assuming there is one.) Will std::ostrstream do the trick?
Yes.
In Java I use java.io.ByteArrayOutputStream to create in-memory data.
When you spit the string from the ostrstream into the output stream,
make sure you flush the buffer. Most of the standard c++ streams (cout,
clog, fstream's, etc.) are buffered by default.


Thanks
-Laurens


Jul 22 '05 #2

P: n/a
"Laurens" <sp**@block.com> wrote:
My application needs to create in-memory arrays, the size of which is not
known, or very hard to calculate, in advance. I would like to stream the
data using the standard I/O class framework. The class should take care of
the underlying memory management. Now which class is most suitable for this?
(Assuming there is one.) Will std::ostrstream do the trick?


Yes, it would. However, you should probably rather use 'std::ostringstream'
because 'std::ostrstream' is deprected: it has several serious problems
which 'std::ostringstream' has not. The only issue which 'std::ostrstream'
solves which 'std::ostringstream' does not is writing to a buffer supplied
by the user. However, a corresponding stream buffer is easy to write and
not what you need if you can't predict the size of the generated output.
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
Phaidros eaSE - Easy Software Engineering: <http://www.phaidros.com/>
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.