gpt4 book ai didi

delphi - InternetReadFile 的常见平均缓冲区大小是多少?

转载 作者:行者123 更新时间:2023-12-02 01:22:54 26 4
gpt4 key购买 nike

我在 Delphi 中使用 WinInet.h 通过 HTTP 下载文件,平均大小在 30 KB 到 1.5 MB 之间。

var
Buf: array[0..BUFFER_SIZE - 1] of Byte;
while BOOL(InternetReadFile(hUrl, @Buf, SizeOf(Buf), BytesRead)) and (BytesRead > 0) do
if Terminated then
Exit
else
begin
FStream.WriteBuffer(Buf, BytesRead);
Synchronize(UpdateProgress);
FillChar(Buf, SizeOf(Buf), 0);
end;

此类下载的建议缓冲区大小是多少 - 既不能太大也不能太小。

最佳答案

对于这样的缓冲区,我通常编码:

var
Buf: array[word] of byte;

分配 64 KB 的缓冲区。

但是,从我的小实验来看,WinINet 太慢了,内部缓冲区大小不会发生太大变化。

如果您追求性能,请查看WinHTTP,它比WinINet快得多。速度快了 10 倍以上,至少对于多个​​连接而言。唯一缺少的功能是用于远程拨号访问的对话框:

Microsoft Windows HTTP Services (WinHTTP) provides developers with a server-supported, high-level interface to the HTTP/1.1 Internet protocol. WinHTTP is designed to be used primarily in server-based scenarios by server applications that communicate with HTTP servers.

WinINet was designed as an HTTP client platform for interactive desktop applications, such as Microsoft Internet Explorer, Microsoft Office, and Microsoft Money. WinINet displays a user interface for some operations such as collecting user credentials. WinHTTP, however, handles these operations programmatically. Server applications that require HTTP client services should use WinHTTP instead of WinINet. For more information, see Porting WinINet Applications to WinHTTP.

WinHTTP is also designed for use in system services and HTTP-based client applications. However, single-user applications that require FTP protocol functionality, cookie persistence, caching, automatic credential dialog handling, Internet Explorer compatibility, or downlevel platform support should consider using WinINet.

Extracted from MSDN

我在我们的开源 ORM 框架中实现了 WinInet 和 WinHTTP 客户端访问。您可以看看这篇博客文章来了解一下more info about WinHTTP .

据我所知,最新版本的IE使用WinHTTP而不是WinINet。所以我们可以考虑朝同一个方向发展。

关于delphi - InternetReadFile 的常见平均缓冲区大小是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6565567/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com