3 ms·
It's only much better if you care about cache misses, right? I think for a 10x10 array we can safely ignore performance concerns.
by bubblyworld 2y ago
It's only much better if you care about cache misses, right? I think for a 10x10 array we can safely ignore performance concerns.
- CyberDildonics 2y agoIt's only much better if you care about cache misses, right? No, not at all. There are cache misses and simplicity, but think about when an 1k image is on the heap. You have to allocate a buffer of pointers for each row then you have do a thousand individual heap allocations to get all your rows. Now think about an image with rgba channels. Technically this is a 3d image with one short dimension. Are you going to allocate a buffer of a thousand pointers, then off of each one allocate a buffer of a thousand more pointers so that you can ultimately do another 1 million heap allocations, all 16 bytes for each rgba pixel? There is no upside and all downsides, which is why it is never ultimately done this way, though it is an almost universal mistake when people do multi-dimensional arrays for the first time.
- bubblyworld 2y agoYeah, I hear you, my point was just that we know the constraints up front and it doesn't matter in this case. Sometimes it's convenient to not have to pass around the length and do one or more multiplies with every index.