Ignore:
Timestamp:
Nov 4, 2011, 11:46:15 AM (13 years ago)
Author:
george
Message:
  • Modified: Method of StreamHelper for reading string data with defined length.
  • Modified: BitStream now use class TPositionMemory from package Common instead of TMemoryStream for storing data. TMemoryStream allocate too huge data (4 kB) even if only few bytes are used.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • CoolStreaming/UStreamHelper.pas

    r269 r291  
    3939    function ReadCardinal: Cardinal;
    4040    function ReadInt64: Int64;
    41     function ReadString: string;
     41    function ReadString(Length: Integer): string;
    4242    function ReadShortString: string;
    4343    function ReadAnsiString: string;
     
    7373begin
    7474  FStream.ReadBuffer(StringLength, SizeOf(StringLength));
    75   SetLength(Result, StringLength);
    76   if StringLength > 0 then begin
    77     FStream.ReadBuffer(Result[1], StringLength);
    78   end;
     75  Result := ReadString(StringLength);
    7976end;
    8077
     
    119116end;
    120117
    121 function TStreamHelper.ReadString:string;
    122 begin
    123   SetLength(Result, FStream.Size - FStream.Position);
    124   if (FStream.Size - FStream.Position) > 0 then
    125     FStream.Read(Result[1], FStream.Size - FStream.Position)
    126     else Result := '';
     118function TStreamHelper.ReadString(Length: Integer): string;
     119begin
     120  if Length > 0 then begin
     121    SetLength(Result, Length);
     122    FStream.Read(Result[1], Length);
     123  end else Result := '';
    127124end;
    128125
     
    132129begin
    133130  FStream.ReadBuffer(Count, 1);
    134   SetLength(Result, Count);
    135   FStream.ReadBuffer(Result[1], Count);
     131  Result := ReadString(Count);
    136132end;
    137133
Note: See TracChangeset for help on using the changeset viewer.