Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You can pack data with primary type arrays in Java for memory (cache) friendly processing. Or go the JNI route, with less portability.


"primary type array"?

Do you mean primitive type array? Because in that case, a bunch of arrays of primitives does not have the same layout and cache locality as an array of structs of primitives.


Just as an aside, sometimes slicing up your arrays-of-structs into structs-of-arrays brings big locality improvements.

Anyway, you can usefully control some aspects of how Java lays out your data, including primitive fields:

http://psy-lob-saw.blogspot.com/2013/05/know-thy-java-object...


And sometimes it brings big locality hits.

Layout within objects is not what I'm talking about here. What I'm talking about is layout of objects within an array. There's no way to do an array of <whatever>. It's an array of <primitive> or an array of <pointer to whatever>. So much pointer-chasing!

In (e.g.) C, I can do either array-of-structs or structs-of-arrays. In Java... I don't know any way to have an array-of-structs in Java (portably, that is).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: