←back to thread

Indices, not Pointers

(joegm.github.io)
102 points vitalnodo | 1 comments | | HN request time: 0.203s | source
Show context
zahlman ◴[] No.45110423[source]
> There is a pattern I’ve learned while using Zig which I’ve never seen used in any other language.

I've done this in small applications in C (where nodes were already being statically allocated) and/or assembly (hacking on an existing binary).

No idea about the effect on speed in general; I was trying to save a few bytes of storage in a place where that mattered.

replies(5): >>45111351 #>>45111431 #>>45111876 #>>45112740 #>>45112993 #
anonymousiam ◴[] No.45111431[source]
But in C, there's not really any difference between pointers and indices. You can access array elements using either method, and they're both equally efficient.
replies(4): >>45111456 #>>45111634 #>>45112113 #>>45112598 #
1. LegionMammal978 ◴[] No.45111456[source]
Depending on how many elements you have, you can save some space using 32-bit or even 16-bit indices in place of 64-bit pointers. (Just make sure there isn't any route to overflow the index type.)