I'm confuse...what is the purpose of this method ?
I'm confuse...what is the purpose of this method ?
function TStream.ReadData(Buffer: Pointer; Count: Longint): Longint;
var
Buf: TBytes;
I: Integer;
begin
SetLength(Buf, Count);
Result := Read(Buf, 0, Count);
for I := 0 to Result - 1 do
PByteArray(Buffer)^[I] := Buf[I];
end;
function TStream.ReadData(Buffer: Pointer; Count: Longint): Longint;
var
Buf: TBytes;
I: Integer;
begin
SetLength(Buf, Count);
Result := Read(Buf, 0, Count);
for I := 0 to Result - 1 do
PByteArray(Buffer)^[I] := Buf[I];
end;
It reads data from a stream and returns the number of bytes read.
ReplyDeleteOr do you mean "Why have this method when there is already TStream.Read which does the same with less overhead?"
For that the answer is probably "backwards compatibility".
Thomas Mueller compatibility with what ?
ReplyDeleteis there any difference with this implementation (that could be inlined)
function TStream.ReadData(Buffer: Pointer; Count: Longint): Longint;
begin
Result := Read(Buffer^, Count);
end;
There is one difference: Even if read overwrites the whole buffer passed to it, this won't affect the bytes at offsets > Result in the buffer passed to ReadData.
ReplyDeleteThomas Mueller I think that is the case in both variants.
ReplyDeleteThe first version will ensure the original buffer is untouched in the case of an exception inside Read. The number of times that is relevant should be minuscule, however :).
Attila Kovacs You're damn right, it's in XE3 version, it has been fixed since then ! good !
ReplyDeleteI work on some tweaks for the VCL and did apply that on a customer's project under XE3