Recent

Author Topic: borland delphi uses borlndmm.dll, whats for lazarus?  (Read 19718 times)

xenblaise

  • Sr. Member
  • ****
  • Posts: 358
Re: borland delphi uses borlndmm.dll, whats for lazarus?
« Reply #15 on: November 21, 2010, 11:21:20 am »
Quote
ype
pmyrec = ^myrec;
myrec = packed record
id:integer;
name:string;
end;
var thisrec:pmyrec;
...
while not DATASET.EOF do begin
if need-to-allocate-space-for-the-next-record then
thisrec:=allocmem(sizeof(thisrec)); //allocates the memory
else
use-one-of-remaining;

thisrec^.id:=1;
thisrec^.name:='somestring_length_1k';
memstream.writebuffer(thisrec,sizeof(thisrec));
end;

Ok;
So, where to put that? like that? whats the code to put? :D

ivan17

  • Full Member
  • ***
  • Posts: 173
Re: borland delphi uses borlndmm.dll, whats for lazarus?
« Reply #16 on: November 21, 2010, 05:16:41 pm »
i spent entire minute seriously considering whether i should answer, but since i have a weak character (and it's not completely trivial) i will calm down and answer:

1) have you actually tried allocating entire memory stream AT ONCE (before you start any reading) with memstream.Size? if it doesn't improve performance (as i believe it will not) then the whole thing is a moot point because you can't even notice the time spent on allocating memory...

2) as for applying what i said, the point is to cut down number of allocations/writes (57 times in this case).  if you were writing stuff into the file, you WOULD feel the difference.
Code: Pascal  [Select][+][-]
  1. var buffer: array [1..57] of myrec;    //allocate room for many records once
  2. var k: integer;
  3.  
  4. ...
  5.  
  6. while not DATASET.EOF do begin
  7.     if k > 57 then begin
  8.         write entire buffer into stream (all records);
  9.         k := 1;  
  10.     end;
  11.     read buffer[k] from dataset
  12.     k := k + 1;
  13. end;

xenblaise

  • Sr. Member
  • ****
  • Posts: 358
Re: borland delphi uses borlndmm.dll, whats for lazarus?
« Reply #17 on: November 22, 2010, 05:23:27 am »
This is my code snippet;
Quote
Type
pmyrec = ^myrec;
myrec = packed record
id:integer;
name:string;
end;
var thisrec:pmyrec;
...
//YOU meant like this;
...
procedure WriteTOmemory;
begin
...
while not DATASET.EOF do
begin

if need-to-allocate-space-for-the-next-record then
thisrec:=allocmem(sizeof(thisrec)); //allocates the memory
else
use-one-of-remaining;


thisrec^.id:=1;
thisrec^.name:='somestring_length_1k';
memstream.writebuffer(thisrec,sizeof(thisrec));
end;
...
end;

procedure ReadfromMemory;
begin
while memstream.position<memstream.size do
begin
memstream.read(streamRec, sizeOf(streamRec));
if streamRec.name='Last_Record_The_Name_You_Can_Trust' then found:=true;
end;
end;
..

And I have a hundreds of thousands of records, it takes 6 seconds to found the last record.
And I don't know where to mix your code to my code, can you do the mixing?
I hope that does improve the memory stream reading, if possible.

Thanks

xenblaise

  • Sr. Member
  • ****
  • Posts: 358
Re: borland delphi uses borlndmm.dll, whats for lazarus?
« Reply #18 on: November 26, 2010, 02:38:03 am »
Oh, probably my usage is correct, no need to optimized. :D

 

TinyPortal © 2005-2018