I have kind of an issue. I am trying to pin a jagged array (which i am using due to the sheer size of the data i am handling):
public void ExampleCode(double[][] variables) {
int nbObservants = variables.Length;
var allHandles = new List<GCHandle>();
double*[] observationsPointersTable = new double*[nbObservants];
double** observationsPointer;
GCHandle handle;
for (int i = 0; i < nbObservants; i++) {
handle = GCHandle.Alloc(variables[i], GCHandleType.Pinned);
allHandles.Add(handle);
observationsPointersTable[i] = (double*) handle.AddrOfPinnedObject(); // no prob here
}
fixed(double** obsPtr = observationsPointersTable) { // works just fine
Console.WriteLine("haha {0}", obsPtr[0][0]);
}
handle = GCHandle.Alloc(observationsPointersTable, GCHandleType.Pinned); // won't work
allHandles.Add(handle);
observationsPointer = (double**) handle.AddrOfPinnedObject();
// ...
foreach (var aHandle in allHandles) {
aHandle.Free();
}
allHandles.Clear();
}
I need to use these double** in multiple parts of my code, and don't really want to explicitly pin them every time I need to use them. It seems to me that, as I can fix them through the usual fixed statement, I should be able to allocate a pinned handle to them.
Is there any way to actually pin a double*[] ?