Reputation: 33
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 copy 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!
Upvotes: 3
Views: 3108
Reputation: 43053
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.
Upvotes: 4
Reputation: 613422
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.
Upvotes: 3
Reputation: 22759
You could still use CopyMemory, just use the address of the fist unsent byte as the source pointer.
Upvotes: 1
Reputation: 16620
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);
Upvotes: 0