Per-thread memory management in C#

后端 未结 3 1098
谎友^
谎友^ 2020-12-16 07:19

Continuing the discussion from Understanding VS2010 C# parallel profiling results but more to the point:

I have many threads that work in parallel (using Parallel.Fo

3条回答
  •  难免孤独
    2020-12-16 08:09

    You could pre-allocate a bunch of objects, and keep them in groups intended for separate threads. However, it's likely that you won't get any better performance from this.

    The garbage collector is specially designed to handle small short-lived objects efficiently. If you keep the objects in a pool, they are long-lived and will survive a garbage collection, which in turns means that they will be copied to the second generation heap. This copying will be more expensive than just allocating new objects.

提交回复
热议问题