collections - Can we implement a C++ style list in Java? -


an arraylist in java "holds" references objects , not actual object data.

i wondering if can implement arraylist in java can contain object data directly instead of references. can java unsafe class used implementation? if yes, performance of list in comparison existing java arraylist?

briefly, no.

java works references objects. you're describing relies on low-level control on memory allocation/usage permitting allocate block of memory 'n' entries. java doesn't work - never have control of memory , jvm @ liberty move objects within memory. ever deal references.

note objects containing references refer further distinct memory blocks, , concept of object being contained within 1 contiguous memory block doesn't exist here.

if want byte array backed memory, directbytebuffer may of use. it's java.nio class built using sun.misc.unsafe class. perhaps serialise/deserialise objects (calculating size in order determine indexing properly). serialisation cost swamp other saving, suspect.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -