dynamic char-buffer vs. stringstream

S

Steffen Conrad

Hi,

I want to buffer a large amount of ASCII-output (some 100 MB).

Therefore I'm asking myself, if when using a stringstream for this would
cause a mentionable loss of performance against a dynamically allocated
char-buffer.

Bye,
Steffen
 
G

Gianni Mariani

Steffen said:
Hi,

I want to buffer a large amount of ASCII-output (some 100 MB).

Therefore I'm asking myself, if when using a stringstream for this would
cause a mentionable loss of performance against a dynamically allocated
char-buffer.


Probably not, but why not measure it ?

It really depends on the operations you want to perform.

If you need a contiguous chunk-o-data then you'll need to use vector as
basic_string is not guarenteed to have a contiguous allocation.
 
T

tom_usenet

Hi,

I want to buffer a large amount of ASCII-output (some 100 MB).

Therefore I'm asking myself, if when using a stringstream for this would
cause a mentionable loss of performance against a dynamically allocated
char-buffer.

Depending on the implementation, stringstream might use up to twice
the memory buffered (e.g. 200MB in your case). I'd suggest using your
own code in this case. You could write your own streambuf that handles
the memory allocation in the way that you want, or you could use
CStdio style code or your own custom code instead.

You should probably profile the stringstream approach first though, to
see whether performance is already acceptable.

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,175
Messages
2,570,942
Members
47,476
Latest member
blackwatermelon

Latest Threads

Top