Is there a memory-efficient replacement of java.lang.String?

后端 未结 15 627
被撕碎了的回忆
被撕碎了的回忆 2020-11-30 19:29

After reading this old article measuring the memory consumption of several object types, I was amazed to see how much memory Strings use in Java:



        
15条回答
  •  南方客
    南方客 (楼主)
    2020-11-30 20:31

    The UseCompressedStrings compiler option seems like the easiest route to take. If you're using strings only for storage, and not doing any equals/substring/split operations, then something like this CompactCharSequence class could work:

    http://www.javamex.com/tutorials/memory/ascii_charsequence.shtml

提交回复
热议问题