trying to store java objects in contiguous memory

后端 未结 4 1459
情歌与酒
情歌与酒 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:22

    No, you can't guarantee this locality of reference.

    By allocating a byte array, or using a mapped byte buffer from the nio packages, you could get a chunk of contiguous memory, from which you can decode the data you want (effectively deserializing the objects of interest from this chunk of memory). However, if you repeatedly access the same objects, the deserialization overhead would likely defeat the purpose.

提交回复
热议问题