效率:8 个数组与多维数组

发布于 2024-12-13 07:44:39 字数 153 浏览 1 评论 0原文

什么更有效? 8 个数组 int8 myArrayx[100],还是多维 int8 myArray[8][100]?我正在使用 Microchip PIC 微控制器的 CCS 编译器,我需要在缓冲区中尽可能快地写入,这就是我提出问题的原因。

What is more efficient? 8 arrays int8 myArrayx[100], or a multidimensional int8 myArray[8][100]? I'm working with CCS compiler for Microchip PIC microcontrollers, and I need to write as fast as possible in a buffer, that is the reason of my question.

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

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

发布评论

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

评论(3

浪推晚风 2024-12-20 07:44:39

我不得不认为多维数组会更快。您有更好的机会(可能有保证?)将这些数组放入连续空间的内存中,而您无法确定 8 个单独的数组将在内存中“靠近”在一起 - 损害您的引用位置。

i would have to think that the multi-dimensional array would be faster. you have a much, much better chance (possibly guaranteed?) of having those arrays being placed into memory in contiguous space whereas you can not be sure that the 8 individual arrays will be "close" together in memory - hurting your locality of reference.

末蓝 2024-12-20 07:44:39

这取决于您最常访问哪些项目。
但很可能这并不重要。唯一的区别是底层内存映射分配。

It depends on which items you would access the most.
But likely it doesn't really matter. Only difference is the underlaying memory map allocation.

动听の歌 2024-12-20 07:44:39

取决于数组的分配方式。如果在堆上,则为单个 multidim。由于引用的局部性,数组对于许多用途来说会更快,并且您可以一次性分配数组,这更简单并且产生的开销更少。

如果在堆栈或静态上,则生成的实际二进制代码可能完全相同。

(我不确定你的设备中是否真的有堆,但我想我还是会提到它;)

Depends on how the arrays are allocated. If on the heap, then a single multidim. array would be faster for many purposes due to locality of reference and you can allocate the array in one go, which is simpler and incurs less overhead.

If on the stack or static, the actual binary code produced might be exactly the same.

(I'm not sure you actually have a heap in your device, but I thought I'd mention it anyway ;)

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