justinstenning / SharedMemory

C# shared memory classes for sharing data between processes (Array, Buffer and Circular Buffer)
https://www.nuget.org/packages/SharedMemory
Other
566 stars 118 forks source link

Limit to the number of arrays -- should we support ArraySegments? #15

Closed kasajian closed 8 years ago

kasajian commented 8 years ago

I tried creating one large array of ints, basically 100 million ints. And I compared it to 10 arrays of 10 million ints. I don't see a see a measurable difference in the processes memory utilization or how long it takes.

Does that mean that if my application requires hundreds, if not thousands of arrays, i should create each of the as a separate array?

If I need to create one big array, I'd probably create an ArraySegment or ArraySlice that works kinda like this: http://referencesource.microsoft.com/#q=ArraySegment

but i may not need to do that!

kasajian commented 8 years ago

I verified that every array takes 578 retained bytes of memory from the garbage collector. So one really shouldn't create a lot of these. Use them only for very large arrays, or use an array slicer to slice up the single array into multiple ones. We'll need a version of ArraySegment to do that.

kasajian commented 8 years ago

See pull request: https://github.com/spazzarama/SharedMemory/pull/16