从指针复制数据?

发布于 2024-09-30 13:25:31 字数 533 浏览 8 评论 0原文

...
  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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

迷路的信 2024-10-07 13:25:31

在 Delphi 中,借助编译器的魔力,您只需通过赋值即可复制记录。

MyData := DataSource^;

动态数组是引用计数的,因此只要您不需要真正的深层复制,赋值也会处理动态数组。通过简单的分配,它们就共享相同的内存。

如果您不想这样做,可以单独复制它们:

MyData.pPitch = Copy(pDataSource^.pPitch, Low(pDataSource^.pPitch), 
                                          High(pDataSource^.pPitch);

In Delphi you can copy a record just by assigning it, thanks to compiler magic.

MyData := DataSource^;

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:

MyData.pPitch = Copy(pDataSource^.pPitch, Low(pDataSource^.pPitch), 
                                          High(pDataSource^.pPitch);
作死小能手 2024-10-07 13:25:31

不可以,动态数组无法使用单个复制命令进行复制。您必须:

  1. 复制每个非数组字段
  2. 对于每个数组
    1. 在目标中创建一个正确大小的新数组
    2. 复制数组成员

如果数组是静态的,会容易得多。在这种情况下,复制整个内存块是可能的。

No, the dynamic arrays cannot be copied with a single copy command. You will have to:

  1. Copy each non-array field
  2. For each array
    1. Create a new array of the correct size in the target
    2. Copy the array members across

It would be much easier if the arrays were static. In that case copying the whole memory block would be possible.

淡笑忘祈一世凡恋 2024-10-07 13:25:31

您可以使用系统单元中声明的移动过程:
system.move(pDataSource^, MyData, sizeof(TAnalyzeInfo));

you can use move procedure declared in the system unit :
system.move(pDataSource^, MyData, sizeof(TAnalyzeInfo));

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文