trying to store java objects in contiguous memory

后端 未结 4 1469
情歌与酒
情歌与酒 2021-02-08 18:33

I am trying to implement a cache-like collection of objects. The purpose is to have fast access to these objects through locality in memory since I\'ll likely be reading multip

4条回答
  •  庸人自扰
    2021-02-08 19:25

    I suggest using a HashMap (no threaded) or Hashtable (threaded) for your cache. Both store an object into an array in the sun jvm. Since all objects in java are passed by reference, this should be represented as an array of pointers in c. My bet is that you are performing premature optimization.

    If you absolutely must have this, you have two options:

    1) Use JNI and write it in c. 2) Get a BIG byte buffer and use ObjectOutputStream to write objects to it. This will probable be VERY SLOW compared to using a hash table.

提交回复
热议问题