3 ms·
A pointer is simply an index into an array which is RAM.
by gumby 3y ago
A pointer is simply an index into an array which is RAM.
- lelandbatey 3y agoConceptually, 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.
- zappb 3y agoPointers are a bit more abstract than that. Since each program has a virtual address space, and said address space is made up of memory pages, even raw pointers need to be translated to the physical address via TLBs. In that sense, indices into arrays are more like pointers than the other way around.
- mrkeen 3y agoBut they point into your RAM, which means you can't store them on disk or pass them over the network.
- gumby 3y agoA minor but legitimate benefit.
- edflsafoiewq 3y agoSoA form also lets you trivially store additional data at every node, eg. if an algorithm needs a flag for each node, you just alloc an array for it.
- senderista 3y agoIt's all just names, all the way down. https://www.dropbox.com/s/mmi46lxk8ipoci0/Principles%20of%20Computer%20System%20Design.pdf?dl=0 https://www.dropbox.com/s/mmi46lxk8ipoci0/Principles%20of%20...