Writing and reading integers to and from disk is fast. Writing 1.5 mil integers 
takes under a ms on a test here.

 

Sample play …

 

Var

 Writecount : integer;

  ArrJBird : array of integer;  

  fStream : TFilestream;

dtstart, dtEnd : TDateTime;

begin

  randomize;

  setLength(ArrJBird, 1500000);

  for i:=0 to 1500000-1 do  ArrJBird[i] := random(1000);

 

  dtstart := Now;

        fStream := TFileStream.Create('c:\temp\myFileOfInts.txt',fmCreate);

        fStream.Seek(0,soFromBeginning);

        writeCount := sizeof(integer)*1500000;

        fStream.Write(ArrJBird[0], writeCount);

        showmessage('101st int='+inttostr(arrJBird[101])); 

        fStream.Destroy;

        Application.ProcessMessages;

       for i:=0 to 1500000-1 do  ArrJBird[i] :=-1;

 

        fStream := TFileStream.Create('c:\temp\myFileOfInts.txt',fmOpenRead);

        fStream.Seek(0,soFromBeginning);

        fStream.read(ArrJBird[0],writeCount);

        showmessage('101st int='+inttostr(ArrJBird[101]));

  dtEnd := now;

  showmessage('write to and read from time: '+FloatToStr(dtEnd - dtStart));

// cleanup;

 

 

From: [email protected] 
[mailto:[email protected]] On Behalf Of John Bird
Sent: Monday, 7 July 2014 8:35 p.m.
To: NZ Borland Developers Group - Delphi List
Subject: [DUG] Saving aray

 

I have a program that builds a very large array (over 1,500,000) of integers, 
and the calculation to fill the array takes quite a while – around 40-50 secs.  
 If there is a quick way to do it, I would save the array to disk if it was 
faster than recalculating it the next time.

 

I am guessing that writing the elements to strings and using CSV etc would be 
quite slow, as it involves quite a lot of processing.   I will run a test to 
see.

 

Is there any really fast way to save such an array to disk?   The numbers range 
between 0 and 256 if that helps.

_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: [email protected]
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to [email protected] with 
Subject: unsubscribe

Reply via email to