You'll still be chasing pointers with these. What you (and myself and many others) are looking for are inline types[0][1] that are part of Project Valhalla[2].
I always thought array elements were contiguous in memory? Is it that the objects are contiguous, but the pointers are not? If so, this does seem pretty expensive and I wonder if there's any workarounds.
Well arrays if elementary types are contiguous, yes. Arrays of objects are arrays of references to instances. The references are contiguous, but they point to instances all over the place.
that makes perfect sense, thank you
Does it strike anyone as odd that something trivial in toy languages from the 70s is a separate project 30 years in and named for the the heaven of the gods in the world of Java?
On the other hand the toy languages from the 70s never caught on. In many workplaces Java is considered the high performance language and most devs would prefer Python/PhP at 1/100th the performance.
I don't know what point you are making, but C had structs in the 70s too and it hasn't been a technical hurdle to implement there either. It's literally a few instructions of asm.
Thanks, you're right on. That's what I'm after and that's exactly what Java needs to be useful for doing high performance computations in a sane fashion.
I switched to java from c in the mid 90's. I remember thinking how ridiculously wasteful it was to allocate an array on classes one at at time rather than as a block of memory. I think I was using berkeley DB at the time in c and it let you do that.
You have direct buffers but that's that...
You can use multiple arrays of primitives, inverting the problem 90%. None of the solutions is optimal, easy to maintain, etc.
Yes there is also the sun.misc.Unsafe class but of course that's skating on thin ice.
That ship has sailed.
What do you mean?
I think there was an opening for a fast safe alternative to C++ in HPC, but I think Rust has taken that spot now. Control over allocation, alignment and placement is important in HPC and imo Java took too long to address these issues.
Records can be combined with inline types when they get there with project Valhalla.