简体   繁体   中英

String Deduplication with Flatbuffers in Java

The Cpp API references a CreateSharedString function to perform String deduplication. It seems there is also a specific shared attribute in the flatbuffers DSL.

Unfortunately, I cannot find an equivalent in the Java API nor any documentation about the shared attribute.

Is it possible to create shared strings with the Java API? if yes, how to do?

Should I maintain a map of Strings and their offset for calls to FlatBufferBuilder#createString and perform a check against this map, or is flatbuffers providing a better mean in Java?

Yes, you can do this yourself, if need be. If you serialize an offset you get from createString in 2 or more places, you are using sharing. Using your own map to see if you have already serialized a string and reusing its offset is fine.

Sadly of course this makes the serialization process slower (and use more memory), but this may be worth it if you have a lot of repeating strings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM