开发者

delphi CopyMemory from index

开发者 https://www.devze.com 2023-03-15 17:24 出处:网络
I am using Delphi 7. Could you tell me if there is or can be found somewhere a procedure which acts like: CopyMemory but I would be able to co开发者_如何转开发py memory from

I am using Delphi 7. Could you tell me if there is or can be found somewhere a procedure which acts like: CopyMemory but I would be able to co开发者_如何转开发py memory from the specific number of byte.

I need something with the following signature:

procedure CopyMemory(Destination: Pointer; Source: Pointer; Length: DWORD; fromByte: Integer);

I need this, because I have to send unsent bytes over tcpip and that's the reason why I have to extract unsent bytes stored in the memory.

I have looked in the source and I would need to rewrite a little asm section. I have not touched asm for years and I would rather stay with something reliable ..

Thanks!


You could use this:

procedure CopyMemory(Destination: Pointer; Source: Pointer; Length, fromByte: Integer);
begin
  move(PAnsiChar(Source)[frombyte],PAnsichar(Dest)[frombyte],Length-fromByte);
end;

And don't rewrite the moving part. Rely on the VCL version. Or use the FastCode version if you need.


procedure CopyMemory(Src, Dest: Pointer; Len: Cardinal; Offset: Integer);
var
  OffsetSrc: ^Byte;
begin
  OffsetSrc := Src;
  inc(OffsetSrc, Offset);
  Move(OffsetSrc^, Dest^, Len);
end;

But I think I'd probably prefer to do the pointer arithmetic outside a helper function.


You could still use CopyMemory, just use the address of the fist unsent byte as the source pointer.


Just pass the address of the first byte you want to copy. Make sure you adjust the length.

Pseudocode:

var
  Dest   : TBytes;
  Source : TBytes;
...
SetLength (Dest, Length (Source) - FromByte);
CopyMemory (@Dest[0], @Source[FromByte], Length (Source) - FromByte);
0

精彩评论

暂无评论...
验证码 换一张
取 消