[fpc-pascal] Get empty memory quickly or... an empty file
Bart
bartjunk64 at gmail.com
Fri Sep 13 15:19:58 CEST 2013
On 9/13/13, Reinier Olislagers <reinierolislagers at gmail.com> wrote:
> I'm working on implementing zip64 support and trying to test things by
> compressing large files or streams using FPC's zip code.
>
> Currently using this to get a huge memorystream filled with the same
> data - so it should compress very well:
> ...
> ContentStream:=TMemoryStream.Create();
> ContentStream.SetSize(1+$FFFFFFFF); //4 bytes+1
Actually 4 GB : 4294967295 + 1 = 4294967296 = 4 * 1024 * 1024 * 1024
> ContentStream.Position:=0;
> Buffer:='A'; //pchar
> for i:=0 to ContentStream.Size-1 do
> begin
> ContentStream.Write(Buffer,1);
> end;
> ContentStream.Position:=0;
> However, I'm sure there must be quicker ways (e.g. less newbie code;
> using OS functions to quickly create empty memor, or alternatively
> create a sparse file and zip the file instead of the stream).
Now you have 4G write calls, resulting in 4G System.Move calls.
Maybe it is faster to create a 1GB datastructure (StringOfChar('A',
1024*1024*1024) and do 4 Write's?
(Untested code!)
Bart
More information about the fpc-pascal
mailing list