zlib 和缓冲区大小
我目前正在尝试在我的一个项目中使用 zlib 进行压缩。我查看了基本的 zlib 教程,我对以下陈述感到困惑:
CHUNK 只是用于馈送数据和提取数据的缓冲区大小 来自 zlib 例程。更大的缓冲区大小会更有效, 特别是对于 inflate() 。如果内存可用,则缓冲区大小为 应使用 128K 或 256K 字节的顺序。
#define CHUNK 16384
在我的例子中,我将始终在输出端有一个可用的小缓冲区(大约 80 字节),并且将通过 zlib 从输入端不断馈送非常小的数据(几个字节)。这意味着我的两侧都不会有更大的缓冲区,但我计划使用更小的缓冲区。
但是我不确定如何解释“更大的缓冲区大小会更有效”。这是指编码效率还是时间/空间效率?
我必须解决这种情况的一个想法是添加更多的缓冲层,这些缓冲层已经从输入中累积并重复刷新到输出。然而,这意味着我必须积累数据并向数据添加更多级别的复制,这也会损害性能。
现在,如果效率仅指时间/空间效率,那么我可以衡量这两种方法的影响并决定使用其中一种。但是,如果实际编码可能受到较小缓冲区大小的影响,则可能很难检测到。
有人有使用 zlib 和非常小的缓冲区的经验吗?
I am currently trying to use zlib for compression in one of my projects. I had a look at the basic zlib tutorial and I am confused by the following statements:
CHUNK is simply the buffer size for feeding data to and pulling data
from the zlib routines. Larger buffer sizes would be more efficient,
especially for inflate(). If the memory is available, buffers sizes on
the order of 128K or 256K bytes should be used.#define CHUNK 16384
In my case I will always have a small buffer already available at the output end (around 80 bytes) and will continually feed very small data (a few bytes) from the input side through zlib. This means I will not hav a larger buffer on either side, but I am planning on using much smaller ones.
However I am not sure how to interpret the "larger buffer sizes would be more efficient". Is this referring to efficiency of the encoding or time/space efficiency?
One Idea I have to remedy this situation would be to add some more layers of buffering had have accumulate from the input and flush to the output repeatedly. However this would mean I would have to accumulate data and add some more levels of copying to my data, which would also hurt performance.
Now if efficiency is just referring to time/space efficiency, I could just measure the impact of both methods and decide on one to use. However if the actually encoding could be impacted by the smaller buffer size, this might be really hard to detect.
Does anyone have an experience on using zlib with very small buffers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这意味着时间效率。如果你给大的输入和输出缓冲区充气,它将在内部使用更快的充气代码。它可以在您喜欢的小缓冲区(甚至大小 1)下正常工作,但速度会更慢。
对于您来说,积累输入并将其喂入更大的块中可能是值得的。您还需要提供更大的输出缓冲区。
It means time efficiency. If you give inflate large input and output buffers, it will use faster inflation code internally. It will work just fine with buffers as small as you like (even size 1), but it will be slower.
It is probably worthwhile for you to accumulate input and feed it to inflate in larger chunks. You would also need to provide larger output buffers.