Difference linq and plinq

前端 未结 5 673
旧巷少年郎
旧巷少年郎 2020-12-11 04:20

What is the difference between these two?

What is the best way to compare ?

It is always better plinq ?

When we use plinq ?

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-11 05:04

    Consider avoiding anonymous types while working with PLINQ because according to Threading in C#, by Joe Albahari:

    anonymous types (being classes and therefore reference types) incur the cost of heap-based allocation and subsequent garbage collection.

    (...)

    stack-based allocation is highly parallelizable (as each thread has its own stack), whereas all threads must compete for the same heap — managed by a single memory manager and garbage collector.

提交回复
热议问题