存储增量下载数据的最佳方式是什么?

发布于 2024-08-27 13:04:20 字数 365 浏览 4 评论 0原文

受到 Chromium 的 sha1 类 的启发,我正在考虑增量存储使用 std::string 下载数据

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

此方法或更好的方法有任何可预见的问题吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

来日方长 2024-09-03 13:04:20

如果你的数据很大并且你可以使用 SGI 的 STL —— 正如他们的文档所说,

与 C 字符串不同,绳索是
非常合理的代表
长字符串,例如编辑缓冲区或
邮件消息。

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.

鱼窥荷 2024-09-03 13:04:20

应该没问题,但您可能需要考虑用绳子而不是绳子。附加到绳索更有效,因为它不能保证所有字节保持连续,这将需要重新分配。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文