Hacker News new | ask | show | jobs
by bremac 882 days ago
As the comment you replied to indicates, both of those APIs perform bounds-checking. In certain tight loops, this can add up to quite a bit of overhead [1]. However, it's not documented, but if you really know what you are doing you can convince the JIT to elide the bounds checks for MemorySegments [2].

[1] https://mail.openjdk.org/pipermail/panama-dev/2023-July/0193...

[2] https://mail.openjdk.org/pipermail/panama-dev/2023-July/0194...

1 comments

As pron mentioned, you can use the internal unsafe API without bound checks, you just need a flag for that