Pregunta

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?

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top