Is there a reason to linearize multidimensional arrays into flat for productivity? I mean, even hypothetically you just take pointer operations from compiler and do them explicitly when counting indexes. So what's the point?

有帮助吗?

解决方案

Making them flat might make them stay in the CPU cache longer (since they're in the same block of memory), which would reduce the number of cache misses and therefore improve performance. But you'd have to profile and benchmark the code to see exactly what the actual performance implications would be with any particular program. Certainly, I wouldn't worry about that sort of thing unless profiling indicated that you should figure out how to optimize with regards to the jagged arrays in order to reduce a performance bottleneck.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top