DEADSOFTWARE

sfs: better memory r/o stream
authorKetmar Dark <ketmar@ketmar.no-ip.org>
Fri, 8 Apr 2016 08:15:24 +0000 (11:15 +0300)
committerKetmar Dark <ketmar@ketmar.no-ip.org>
Fri, 8 Apr 2016 08:15:46 +0000 (11:15 +0300)
src/sfs/xstreams.pas

index 20a503f6edb1a3fd3ba8a59b5cab8fbea40137b6..1861c616d0972578f2fcb967dc051dc4e9fc9443 100644 (file)
@@ -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;