Caching in C #

I just saw a very interesting conversation by Herb Sutter at a 2014 construction conference called "Modern C ++: What You Need to Know." Here's a link to the video call: http://channel9.msdn.com/Events/Build/2014/2-661

One of the topics of discussion was how std::vectorvery convenient for caching, mainly because it ensures that its elements are contiguous on the heap, which has a big impact on spatial locality, or at least what I think I understand ; this is even the case for inserting and deleting elements. Smart use std::vectorcan lead to significant performance improvements through the use of caching.

I would like to try something like that with C # /. Net, but how to ensure that objects in my collections are contiguous in memory?

Any other resource pointer is also welcome for caching convenience in C # and .Net. :)

+4
source share
3 answers

It seems that the only way to achieve this in C # is to use value types, which means using structures instead of classes. Using List will then store your objects in continuous memory. You can read more about structures and classes here: Choosing between a class and a structure

+3
source

List, (, std::vector). . .

+1

, GC, , . , , , . , ( ), , .. () , , , ​​ , , .

, , , , -, . , , , .

, ++, : OOP, , , , , ( ) , , RTTI .., .. , # Java, - , , , , , .

(struct, #):

, , # Java C ++, , , . , Java raytracer, , , . , , raytracer - , (BVH, , ) int[] float[]. "", , "", ++ ( C Fortran), raytracer.

, , , , GC GC (: Eden GC). , . 1 - 0 2. , , , , Java #, POD ( structs # , ), .

, , , , , , , , , . Image ( ), , Pixel . Image, . .

new .

new , . : new , , , new . , #, , .., , , .

, .

, OOP , ECS , : Dog Mammal, Cat Mammal. , , , Cats inherit Mammals, Dogs inherit Mammals. Mammals , -, . , , , , Dogs, Mammals, Mammals.

, C ++ Java # - . , , , , , . - , , , Pixel IPixel, , , . Pixel Image, Mammal Mammals, .

+1

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


All Articles