Understanding of .NET internal StringBuilderCache class configuration

后端 未结 2 2561
情歌与酒
情歌与酒 2021-02-20 16:03

When I was looking at decompiled .NET assemblies to see some internals, I\'ve noticed interesting StringBuilderCache class used by multiple framework\'s methods:

2条回答
  •  耶瑟儿~
    2021-02-20 16:42

    Most strings built are probably small, so using a relatively small buffer size will cover most of the operations while not using up too much memory. Consider that there is a thread pool with possibly many threads being created. If every one of them would take up to 2kB for a cached buffer, it would add up to some amount of memory.

提交回复
热议问题