memcpy 适用于结构中的大型数组吗?

发布于 2024-09-07 13:26:23 字数 281 浏览 2 评论 0原文

我有一个结构,里面有一个动态数组。我已经定义了其中两个结构。

我在第一个结构中填充数组,然后使用像

memcpy(R->v, A->v, A->n*sizeof(double) 这样的

行,其中 v 是已动态分配的数组,并且n 是条目的数量,

如果重要的话,

问题是,这些值没有被正确复制到 R 中。知道为什么吗?称为“very_huge_loop”,但没有异常或任何异常,

该数组的长度约为 188k 双倍,

谢谢。

I have a structure that has a dynamic array in it. I have defined two of these structures.

I fill the array in the first structure, then use a line like

memcpy(R->v, A->v, A->n*sizeof(double)

where v is the array that has been dynamically allocated, and n is the number of entries.

R and A are the same type if that matters.

The problem is, the values are not being properyl copied into R. Any idea why? When I try to debug this in totalview, memcpy goes into a function called "very_huge_loop", but no exception or anything is thrown.

the array is approx 188k doubles in length.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

还如梦归 2024-09-14 13:26:23

可能是内存对齐。某些体系结构不喜欢像 double 这样的多字节值从任意字节地址开始。分配数组内存时,您可能需要使用诸如 memalign() 之类的函数,而不是 malloc()。如果您使用的是new double[n],那么它应该已经正确对齐。

It could be memory alignment. Some architectures do not like multi-byte values like double to start on any arbitrary byte address. When you allocate the array memory, you might want to use a function like memalign() instead of malloc(). If you are using new double[n] then it should already be aligned correctly.

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