B
buu
are there any benefits?
performance?
performance?
buu said:I have a unmanaged array declared with:
int* arr;
instanced with:
arr = new int[100];
how could I create property that would return managed array?
sorry, but I'm newbie
anonymous said:Unmanaged arrays should come witha performance boost. Everytime you
reference an element in a Managed array the framework needs to do a
runtime
check in order to make sure you have not gone outside the bounds of the
array, whereas referencing an unmanaged array is just pointer arithmitec.
That being said I don't believe the overhead of a managed array is
significant and the added safety is extremely beneficial. Personally I
use
managed arrays whenever possible.
anonymous said:You will need to convert your unmanaged array to a managed array.
Fortunately there is a class in the System::Runtime::InteropServices
namespace that will help with this called Marshal. Here is code snippet
that
should work:
property array<int>^ ManagedArr{
array<int>^ get() {
//We need to create an IntPtr that wraps arr in order to use Marshal
IntPtr arrPtr(arr);
array<int>^ managedArr = gcnew array<int>(ARRAY_SIZE);
Marshal::Copy(arrPtr, managedArr, 0, ARRAY_SIZE);
return arrPtr;
}
}
buu said:I have a unmanaged array declared with:
int* arr;
instanced with:
arr = new int[100];
how could I create property that would return managed array?
sorry, but I'm newbie
anonymous said:Unmanaged arrays should come witha performance boost. Everytime you
reference an element in a Managed array the framework needs to do a
runtime
check in order to make sure you have not gone outside the bounds of the
array, whereas referencing an unmanaged array is just pointer
arithmitec.
That being said I don't believe the overhead of a managed array is
significant and the added safety is extremely beneficial. Personally I
use
managed arrays whenever possible.
:
are there any benefits?
performance?
anonymous said:You will need to convert your unmanaged array to a managed array.
Fortunately there is a class in the System::Runtime::InteropServices
namespace that will help with this called Marshal. Here is code snippet
that
should work:
property array<int>^ ManagedArr{
array<int>^ get() {
//We need to create an IntPtr that wraps arr in order to use Marshal
IntPtr arrPtr(arr);
array<int>^ managedArr = gcnew array<int>(ARRAY_SIZE);
Marshal::Copy(arrPtr, managedArr, 0, ARRAY_SIZE);
return arrPtr;
}
}
buu said:I have a unmanaged array declared with:
int* arr;
instanced with:
arr = new int[100];
how could I create property that would return managed array?
sorry, but I'm newbie
anonymous said:Unmanaged arrays should come witha performance boost. Everytime you
reference an element in a Managed array the framework needs to do a
runtime
check in order to make sure you have not gone outside the bounds of the
array, whereas referencing an unmanaged array is just pointer
arithmitec.
That being said I don't believe the overhead of a managed array is
significant and the added safety is extremely beneficial. Personally I
use
managed arrays whenever possible.
:
are there any benefits?
performance?
anonymous said:You will need to convert your unmanaged array to a managed array.
Fortunately there is a class in the System::Runtime::InteropServices
namespace that will help with this called Marshal. Here is code snippet
that
should work:
property array<int>^ ManagedArr{
array<int>^ get() {
//We need to create an IntPtr that wraps arr in order to use Marshal
IntPtr arrPtr(arr);
array<int>^ managedArr = gcnew array<int>(ARRAY_SIZE);
Marshal::Copy(arrPtr, managedArr, 0, ARRAY_SIZE);
return arrPtr;
}
}
buu said:I have a unmanaged array declared with:
int* arr;
instanced with:
arr = new int[100];
how could I create property that would return managed array?
sorry, but I'm newbie
anonymous said:Unmanaged arrays should come witha performance boost. Everytime you
reference an element in a Managed array the framework needs to do a
runtime
check in order to make sure you have not gone outside the bounds of the
array, whereas referencing an unmanaged array is just pointer
arithmitec.
That being said I don't believe the overhead of a managed array is
significant and the added safety is extremely beneficial. Personally I
use
managed arrays whenever possible.
:
are there any benefits?
performance?