how can I convert array<int^>^
to int*
?
A:
Name of the array is the address of first element in the array.
int array[] = {1, 2, 3, 4, 5};
int* p = array;
Hemant
2010-08-25 10:34:28
Yes, we know. But this doesn't answer the question.
klez
2010-08-25 10:36:10
assume I have:array<int^> ^p;and I want to pass p as an argument to f(int* input);what should I do?
HPT
2010-08-25 10:36:56
A:
I think it will be hard to directly convert array<int^>^
into an int*
, because it is an array of references to ints, not an array of ints. There is no promises about the memory layout of the integers themselves, which is required in order to get them to a plain old C/C++ array.
I think that the easiest way to go is to make a copy of the array, pass it to f(int* input)
and then possibly copy the data back if it is modified by f.
Anders Abel
2010-08-25 10:40:26
+1
A:
You cannot, at least not the simple way.
If you mean array<int>^
to int*, you can do following:
array<int>^ arr;
cli::pin_ptr<int> pArrayElement = &arr[0];
and then use classical pointer arithmetic over the pin_ptr
.
Yossarian
2010-08-25 10:44:48