delphi - Delphi中复制带偏移量的内存

标签 delphi memory copy

我想复制一个带有偏移量的内存块,可以吗?

这是我到目前为止的代码:

const
  SOURCE: array [0..5] of Byte = ($47, $49, $46, $38, $39, $61);
var
  Destination: Pointer;
begin
  // This is a full copy
  Move(SOURCE, Destination^, SizeOf(SOURCE));

  // If i want to copy from the third byte, is it possible?
  // I imagine the code should be, but it cannot be compiled.
  Move(Slice(SOURCE^, {Offset=}2)^, Destination^, SizeOf(SOURCE) - 2);
end;

最佳答案

尚不完全清楚你想要实现什么,但看起来像

MoveMemory(pointer(NativeUInt(Destination) + 2), @SOURCE[0], SizeOf(SOURCE) - 2)

虽然我怀疑你真的想要

MoveMemory(pointer(NativeUInt(Destination) + 2), @SOURCE[2], SizeOf(SOURCE) - 2)

关于delphi - Delphi中复制带偏移量的内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10674763/

相关文章:

ios - swift : Game starts to lag mid way

c++ - 如何使用 sigsegv 捕获内存读取和写入?

delphi - 检测Windows服务状态

delphi - 有没有办法将默认堆栈大小增加到超过 16777216 字节?

mongodb - 使用来自 Grijjy 的 DelphiMongoDB 对 MongoDB 进行身份验证

python - 限制 RAM : python crashes instead of MemoryError

javascript - jQuery 文本编辑器 : keep format when I copy & paste text from somewhere else

ios - swift 启用使用 copy() 或 unshare method()

java - 如何使用 for 循环将返回对象数组复制到另一个数组

delphi - cxGrid 仅限大写字母