* Change buffer to dyn array

This commit is contained in:
Michaël Van Canneyt 2025-03-18 17:17:24 +01:00
parent db7abc11d6
commit ec3ed04b73

View File

@ -24,7 +24,9 @@ unit owbase;
{$i fpcdefs.inc} {$i fpcdefs.inc}
interface interface
uses uses
globtype,
cstreams, cstreams,
cclasses; cclasses;
@ -33,7 +35,7 @@ type
private private
f : TCCustomFileStream; f : TCCustomFileStream;
opened : boolean; opened : boolean;
buf : pchar; buf : TAnsiCharDynArray;
bufidx : longword; bufidx : longword;
procedure writebuf; procedure writebuf;
protected protected
@ -61,7 +63,7 @@ type
private private
f : TCCustomFileStream; f : TCCustomFileStream;
opened : boolean; opened : boolean;
buf : pchar; buf : TAnsiCharDynArray;
ffilename : string; ffilename : string;
bufidx, bufidx,
bufmax : longint; bufmax : longint;
@ -104,7 +106,7 @@ const
constructor tobjectwriter.create; constructor tobjectwriter.create;
begin begin
getmem(buf,bufsize); setlength(buf,bufsize);
bufidx:=0; bufidx:=0;
opened:=false; opened:=false;
fsize:=0; fsize:=0;
@ -115,7 +117,7 @@ destructor tobjectwriter.destroy;
begin begin
if opened then if opened then
closefile; closefile;
freemem(buf,bufsize); buf:=nil;
end; end;
constructor tobjectwriter.createAr(const Aarfn:string); constructor tobjectwriter.createAr(const Aarfn:string);
@ -160,7 +162,7 @@ end;
procedure tobjectwriter.writebuf; procedure tobjectwriter.writebuf;
begin begin
f.write(buf^,bufidx); f.write(buf[0],bufidx);
bufidx:=0; bufidx:=0;
end; end;
@ -183,6 +185,8 @@ begin
while len>0 do while len>0 do
begin begin
bufleft:=bufsize-bufidx; bufleft:=bufsize-bufidx;
if bufleft=0 then
Writebuf;
if len>bufleft then if len>bufleft then
begin begin
move(p[idx],buf[bufidx],bufleft); move(p[idx],buf[bufidx],bufleft);
@ -275,8 +279,8 @@ begin
end; end;
ffilename:=fn; ffilename:=fn;
bufmax:=f.Size; bufmax:=f.Size;
getmem(buf,bufmax); setlength(buf,bufmax);
f.read(buf^,bufmax); f.read(buf[0],bufmax);
f.free; f.free;
bufidx:=0; bufidx:=0;
opened:=true; opened:=true;
@ -289,7 +293,7 @@ begin
opened:=false; opened:=false;
bufidx:=0; bufidx:=0;
bufmax:=0; bufmax:=0;
freemem(buf); buf:=Nil;
end; end;