Heap fragmentation when using byte arrays

前端 未结 3 1894
闹比i
闹比i 2021-02-05 10:54

I have a C# 4.0 application (single producer/single consumer) which transfers huge amount of data in chunks. Although there\'s no new memory allocation I run out of memory after

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-05 11:30

    You probably ran into the large object heap problem - objects larger than 85,000 bytes are put on the large object heap which is not compacted which can lead to strange out of memory situations. Although apparently the performance in .NET 4 has been improved it's far from perfect. The solution is to basically use your own buffer pool which contains a few statically allocated chunks of memory and reuse those.
    There is a whole bunch of questions around that on SO.

    Update: Microsoft provides a buffer manager as part of the WCF stack. There is also one on codeproject.

提交回复
热议问题