Getting a raw pointer to int from unmanaged C++ - Code
-
Dear developers, my managed C#-Code calls an unmanaged C++-Class-Method which allocates an array of integers (int *pInt = new int [5])and returns a reference to this array. How can I use this reference in my C#-Code without copying the values in the array. So far I didn't find any solution. Kind regards
-
Dear developers, my managed C#-Code calls an unmanaged C++-Class-Method which allocates an array of integers (int *pInt = new int [5])and returns a reference to this array. How can I use this reference in my C#-Code without copying the values in the array. So far I didn't find any solution. Kind regards
Hi, AFAIK you can't. The only way I am aware of that avoids copying is by allocating the array on the managed side, pass it to the unmanaged side, and let it fill it there. The rationale is the managed metadata needs to be added to the raw data, and .NET is unable to do that for existing data. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Voting for dummies? No thanks. X|
-
Hi, AFAIK you can't. The only way I am aware of that avoids copying is by allocating the array on the managed side, pass it to the unmanaged side, and let it fill it there. The rationale is the managed metadata needs to be added to the raw data, and .NET is unable to do that for existing data. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Voting for dummies? No thanks. X|