简体   繁体   English

是不是Delphi TFileStream WriteBuffer Int64的大小?我一次只能写少量

[英]Isn't the size of Delphi TFileStream WriteBuffer Int64? I'm only able to write small amounts at a time

I'm trying to write larger chunks to increase the speed of the file save. 我正在尝试编写更大的块来提高文件保存的速度。 I have about 9 of these loops to convert but I can't figure out what I'm doing wrong 我有大约9个这些循环要转换,但我无法弄清楚我做错了什么

fs := TFileStream.Create(Myfile, fmCreate);

This code works: 此代码有效:

for RecordGroup := 0 to TotalGroups - 1 do
begin
  for RecordNumber := 0 to Length(MyArray[RecordGroup]) - 1 do
  begin
    fs.WriteBuffer(MyArray[RecordGroup,RecordNumber],SizeOf(MyRecord));
  end;
end;

When I remove the innerloop to write bigger chunks, the code does not work: 当我删除内部循环以编写更大的块时,代码不起作用:

for RecordGroup := 0 to TotalGroups - 1 do
begin
  fs.WriteBuffer(MyArray[RecordGroup],SizeOf(MyRecord) * Length(MyArray[RecordGroup]));
end;

I get the generic error 'Stream write error' 我得到通用错误'Stream write error'

The value of SizeOf(MyRecord) * Length(MyArray[RecordGroup]) is 180 * 152,004 = 27,360,720 SizeOf(MyRecord) * Length(MyArray[RecordGroup])值为180 * 152,004 = 27,360,720

Everything I've read basically says this is correct. 我读过的所有内容基本上都说这是正确的。 Any ideas what I'm doing wrong? 我有什么想法我做错了吗?

Thanks in advance for any ideas you may have. 提前感谢您的任何想法。

Change writing code to (note additional 0 in square brackets) 将编写代码更改为(注意方括号中的附加0)

fs.WriteBuffer(MyArray[RecordGroup, 0],   SizeOf(MyRecord) * Length(MyArray[RecordGroup]));

Mistake was in wrong dynamic array usage. 错误是动态数组使用错误。 I assume that MyArray is two-dimensional array, so MyArray[RecordGroup] is 1D dynamic array - essentially pointer to data - but untyped var-parameter of WriteBuffer requires using of array data body. 我假设MyArray是二维数组,因此MyArray[RecordGroup]是一维动态数组 - 本质上是指向数据的指针 - 但WriteBuffer无类型var参数需要使用数组数据体。


Aside note - your for-loop counter goes from 0 to TotalGroups , so overall number of loops is TotalGroups + 1 . 除了注意 - 你的for循环计数器从0到TotalGroups ,所以循环的TotalGroups + 1TotalGroups + 1 Is it correct? 这是对的吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM