4 ms·
Conceptually, yes. There are a lot of finer points to this concept though. One of the points most relevanthere is that accessing "RAM" is not _actually_ an O(1)
by lelandbatey 3y ago
Conceptually, yes. There are a lot of finer points to this concept though. One of the points most relevanthere is that accessing "RAM" is not _actually_ an O(1) operation, due to CPU caches which can speed up sequential access of "close together" data. Thus, if you manually ensure that data is "close together" (by putting it all in an array together), you can massively speed up your program in the real world because now all your keys/data can be squeezed into the cache at once.
- gumby 3y agoYou can allocate your data the same way, especially using custom allocators in C++. And every reference requires some arithmetic too, if you're worrying about that. But my point is that storing them in another array doesn't buy you a lot if you allow deallocations (you can then still have a use-after-free, or even read the wrong object) while if you don't deallocate you might as well just use pointers. Just trying to understand the benefit of going to all this work. I can see the point in old FORTRAN code before FORTRAN 90
- lelandbatey 3y agoI think it's mostly just an experiment, example, proof-of-concept or other "toy" implementation demonstrating/exploring the idea.
- gumby 3y agoYeah, no judgement on that. But I’ve worked with indexed classes (mixin class) to avoid pointers in the past and have never found them worth the effort. Since someone else is mentioning it here on HN I’m asking if there is an advantage over pointers that I don’t realise — if so I might be glad to take advantage of it myself.