tags:

views:

30

answers:

2

Inspired by Chromium's sha1 class, I am thinking to store incrementally downloaded data using std::string

// pseudo-code
char buff[BUFF_SIZE];
std::string data;
do {
    size = ReadInternetFileTo(buff,BUFF_SIZE);
    data.append(buff,size);
} while (not_finished);

Any foreseeable problems with this method or better way to do it?

+1  A: 

Should be OK, but you may want to consider rope instead of string. It is more efficient to append to a rope, as it won't promise to keep all bytes consecutive, which will require a reallocation.

Stephen
+2  A: 

SGI's good old Rope seems like a great fit, if your data's large and you can use SGI's STL -- as their docs say,

Unlike C strings, ropes are a reasonable representation for very long strings such as edit buffers or mail messages.

Alex Martelli