C # Local heaps for threads in a multi-threaded process

I have a multi-threaded process in C #, and each thread often tries to allocate memory from the heap. This entails multiple blocking of the heap and, therefore, reduces the advantage when cutting.

Is there something like local heaps for threads, so a simultaneous attempt to allocate memory from different threads would not block one of them?

+4
source share
1 answer

According to this article , in a multiprocessor system there is no competition when several threads allocate memory at the same time:

Distributions without synchronization In a multiprocessor system, generation 0 of the managed heap is divided into several memory arenas using one arena for each thread. This allows you to create multiple distribution threads at the same time, so exclusive access to the heap is required.

EDIT: Hans Passant correctly pointed out that in order for this behavior to apply, the garbage collector must be forced into gcServer mode in the workstation environment. This is done by editing the app.config or web.config and providing the following parameters:

 <configuration> <runtime> <gcServer enabled="true"/> </runtime> ... </configuration> 
+5
source

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


All Articles