Heap fragmentation when using byte arrays

前端 未结 3 1891
闹比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:39

    How long are your byte[] array? Do they fall into the small object or large object heap? If you experience memory fragmentation, I would say they fall into the LOH.

    You should therefore reuse the same byte arrays (use a pool) or use smaller chunks. The LOH is never compacted, so it can become quite fragmented. Sadly there is no way around this. (Apart from knowing this limitation and avoiding it)

提交回复
热议问题