Hello everyone!
Quick question: In the API examples for the 2000A-Series (possibly others, that's the one I know so far ) the arrays passed to the GetValues and GetTimesAndValues methods are pinned (PinnedArray) and have to be fully initialized beforehand.
Why is this necessary and in what situation would it become problematic if not using a pinned array?
Does it have performance/speed implications?
I am using GCLatencyMode.Batch and did not have any trouble so far.
You need to use pinned arrays because you are passing these from your managed code to an unmanaged C++ dll, and their location in memory needs to be fixed so that the dll can safely write to the space.
Hey Martyn, thanks for the answer!
I am using unpinned arrays for a while and have not encountered a problem even once.
So I am wondering now, how one would go about writing tests for this scenario
But that's a question for a different forum, I guess
BTW, the quality of your products is immensely appreciated.
for C# you
use a function that allocate 250 array's of random length between 200000 and 300000 integers and write them all with some number not 0
Then exit this function.
Hi bennog!
Interesting idea. If I understand correctly, I would write a C function that does 'something' (like iterating, maybe) over the arrays, and that function, should start to see discrepancies, right?
If I put increments of 1 in the arrays and check on the C side, data would get discontinous.
it is only needed where you use managed code like C# that use garbage collect.
And if you fragment the memory on C# and allocate and release a lot of various memory sizes, C# has the nasty habit of moving memory around to different physical addresses. So unmaaged code writes to the wrong addresses.
If you use C or C++ there is no need because these don't have a garbage collect, even C++ smart pointers do not shuffle memory around.
I'm curious what the decision was, not to use the "fixed" statement here, as it would make "unpinning" of the arrays unnecessary and we could just use regular GC routines.
Ah yes, the unsafe-scare I totally forgot about that. Good point…
But as I understood it, there's actually more difference between pinning via GCHandle and fixed segments. THE Hans Passant has an interesting answer over at SO, but I am not knowledgeable enough about GC internals to fully grasp it.