简体   繁体   中英

StringBuilder backed up by a linked list

I notice that StringBuilder is backed up by an array, which makes it allocate a single memory block. I don't like that behavior because the memory is highly fragmented and somtimes it's hard to find a big enough block of memory, which triggers the GC...

I wonder if there is a version of StringBuilder backed up by a linked list, which would be more memory-friendly.

First of all I'd seriously question the need for an alternative: for most use-cases the implementation of StringBuilder is perfectly sensible and works just fine. Measure before you decide.

If you indeed need similar objects of such enormous size that this becomes a problem, then something like Ropes for Java might help: It's effectively a library of many different CharacterSequence implementations (with a common interface Rope ) optimized for different interactions.

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