从指针复制数据?
...
PAnalyzeInfo = ^TAnalyzeInfo;
TAnalyzeInfo = record
pPitch: array of Single;
pEnergy: array of Single;
pPitchAccent: array of Single;
pEnergyAccent: array of Single;
pDicAccent: array of Single;
pScore: array of Single;
pBoundary: Integer;
szRecWord: array of array of AnsiChar;
nRecWordNum: Integer;
nFrameNum: Integer;
end;
...
我有 pDataSource: PAnalyzeInfo
其中包含数据,我想将其复制到新的自变量。 我的数据:TAnalyzeInfo
。
是否可以复制整个结构或逐个添加它?
...
PAnalyzeInfo = ^TAnalyzeInfo;
TAnalyzeInfo = record
pPitch: array of Single;
pEnergy: array of Single;
pPitchAccent: array of Single;
pEnergyAccent: array of Single;
pDicAccent: array of Single;
pScore: array of Single;
pBoundary: Integer;
szRecWord: array of array of AnsiChar;
nRecWordNum: Integer;
nFrameNum: Integer;
end;
...
I have pDataSource: PAnalyzeInfo
which contains data and I want to copy it to a new independent variable. MyData : TAnalyzeInfo
.
Is it possible to copy the whole structure or adding it one bye one?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 Delphi 中,借助编译器的魔力,您只需通过赋值即可复制记录。
动态数组是引用计数的,因此只要您不需要真正的深层复制,赋值也会处理动态数组。通过简单的分配,它们就共享相同的内存。
如果您不想这样做,可以单独复制它们:
In Delphi you can copy a record just by assigning it, thanks to compiler magic.
The dynamic arrays are reference counted, so the assignment also takes care of the dynamic arrays as long as you don't need a real deep copy. With a simple assignment they just share the same memory.
If you don't want that you can copy them individually:
不可以,动态数组无法使用单个复制命令进行复制。您必须:
如果数组是静态的,会容易得多。在这种情况下,复制整个内存块是可能的。
No, the dynamic arrays cannot be copied with a single copy command. You will have to:
It would be much easier if the arrays were static. In that case copying the whole memory block would be possible.
您可以使用系统单元中声明的移动过程:
system.move(pDataSource^, MyData, sizeof(TAnalyzeInfo));
you can use move procedure declared in the system unit :
system.move(pDataSource^, MyData, sizeof(TAnalyzeInfo));