From: Ketmar Dark Date: Fri, 8 Apr 2016 08:15:24 +0000 (+0300) Subject: sfs: better memory r/o stream X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=9b23fafe854f9ff68379ba581f009beade3f6810;p=d2df-sdl.git sfs: better memory r/o stream --- diff --git a/src/sfs/xstreams.pas b/src/sfs/xstreams.pas index 20a503f..1861c61 100644 --- a/src/sfs/xstreams.pas +++ b/src/sfs/xstreams.pas @@ -85,8 +85,13 @@ type end; TSFSMemoryStreamRO = class(TCustomMemoryStream) + private + fFreeMem: Boolean; + fMem: Pointer; + public - constructor Create (pMem: Pointer; pSize: Integer); + constructor Create (pMem: Pointer; pSize: Integer; aFreeMem: Boolean=false); + destructor Destroy (); override; function Write (const buffer; count: LongInt): LongInt; override; end; @@ -286,13 +291,20 @@ end; { TSFSMemoryStreamRO } -constructor TSFSMemoryStreamRO.Create (pMem: Pointer; pSize: Integer); +constructor TSFSMemoryStreamRO.Create (pMem: Pointer; pSize: Integer; aFreeMem: Boolean=false); begin + fFreeMem := aFreeMem; + fMem := pMem; inherited Create(); SetPointer(pMem, pSize); Position := 0; end; +destructor TSFSMemoryStreamRO.Destroy (); +begin + if fFreeMem and (fMem <> nil) then FreeMem(fMem); +end; + function TSFSMemoryStreamRO.Write (const buffer; count: LongInt): LongInt; begin result := 0;