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;
}
}
[quoted text, click to view] "buu" wrote:
> 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" <anonymous@discussions.microsoft.com> wrote in message
> news:0EA68CE2-C552-4A7B-9C9B-10C8852E6263@microsoft.com...
> > 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.
> >
> > "buu" wrote:
> >
> >> are there any benefits?
> >>
> >> performance?
> >>
> >>
> >>
>
>
it seems ok, but after that, inside the class, I have a memset(arr) command,
and I got an memory corruption error.
[quoted text, click to view] "anonymous" <anonymous@discussions.microsoft.com> wrote in message
news:D18112CC-C79F-4F9B-B603-E7CCB9483629@microsoft.com...
> 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" wrote:
>
>> 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" <anonymous@discussions.microsoft.com> wrote in message
>> news:0EA68CE2-C552-4A7B-9C9B-10C8852E6263@microsoft.com...
>> > 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.
>> >
>> > "buu" wrote:
>> >
>> >> are there any benefits?
>> >>
>> >> performance?
>> >>
>> >>
>> >>
>>
>>
>>
it seems ok, but after that, inside the class, I have a memset(arr) command,
and I got an memory corruption error.
[quoted text, click to view] "anonymous" <anonymous@discussions.microsoft.com> wrote in message
news:D18112CC-C79F-4F9B-B603-E7CCB9483629@microsoft.com...
> 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" wrote:
>
>> 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" <anonymous@discussions.microsoft.com> wrote in message
>> news:0EA68CE2-C552-4A7B-9C9B-10C8852E6263@microsoft.com...
>> > 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.
>> >
>> > "buu" wrote:
>> >
>> >> are there any benefits?
>> >>
>> >> performance?
>> >>
>> >>
>> >>
>>
>>
>>
it seems ok, but after that, inside the class, I have a memset(arr) command,
and I got an memory corruption error.
[quoted text, click to view] "anonymous" <anonymous@discussions.microsoft.com> wrote in message
news:D18112CC-C79F-4F9B-B603-E7CCB9483629@microsoft.com...
> 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" wrote:
>
>> 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" <anonymous@discussions.microsoft.com> wrote in message
>> news:0EA68CE2-C552-4A7B-9C9B-10C8852E6263@microsoft.com...
>> > 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.
>> >
>> > "buu" wrote:
>> >
>> >> are there any benefits?
>> >>
>> >> performance?
>> >>
>> >>
>> >>
>>
>>
>>