StringBuilder supported by linked list

I notice that StringBuilder backed up by an array, which allows you to allocate one block of memory. I do not like this behavior because the memory is very fragmented and it is sometimes difficult to find a large enough block of memory that runs GC ...

I wonder if there is a version of StringBuilder copied by a linked list that will be more memory friendly.

+4
source share
1 answer

First of all, I would seriously question the need for an alternative: for most use cases, StringBuilder is perfectly reasonable and works StringBuilder fine. Measure before making a decision.

If you really need such objects of such huge size that it becomes a problem, then something like Ropes for Java can help: effectively a library of various implementations of CharacterSequence (with a common Rope interface), optimized for different interactions.

+3
source

Source: https://habr.com/ru/post/1437570/


All Articles