Streams
From: Mark D. Lincoln (mdlincoln_at_speakeasy.net)
Date: 12/29/03
- Next message: kin: "Year 2004"
- Previous message: Didier Cabalé: "Re: how to destroy an object when one need to end his procedure"
- Next in thread: Erwin Molendyk: "Re: Streams"
- Reply: Erwin Molendyk: "Re: Streams"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 29 Dec 2003 17:51:16 -0500
All,
It seems that allocating a buffer for a stream to read to and and write from
is a bit strange. Can someone explain why one might do the following:
var
oStream : TMemoryStream;
sStream : string;
begin
oStream.Position := 00;
SetLength( sStream, self.Size );
oStream.Read( Pointer( sStream )^, self.Size ); // Note the use of the
Pointer cast
end;
verus the following:
var
oStream : TMemoryStream;
sStream : string;
begin
oStream.Position := 00;
SetLength( sStream, self.Size );
oStream.Read( sStream[ 01 ], self.Size );
end;
Why use the Pointer( sStream )^ in one case and the sStream[ 01 ] in
another. What is the difference? Is one better, faster, or more stable
than the other? This also seems to apply to the Write() method as well. I
have seen both of the following:
oStream.Write( Pointer( sWrite )^, Length( sWrite ) );
and:
oStream.Write( sWrite[ 01 ], Length( sWrite ) );
It has been been my experience with this one that the former Write() is more
stable that the latter if the string is null since a null string causes a
nasty access violation when trying to work with sWrite[ 01 ]. Can anyone
shed some more light on this?
Mark
- Next message: kin: "Year 2004"
- Previous message: Didier Cabalé: "Re: how to destroy an object when one need to end his procedure"
- Next in thread: Erwin Molendyk: "Re: Streams"
- Reply: Erwin Molendyk: "Re: Streams"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|