Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / September 2007

Tip: Looking for answers? Try searching our database.

benefits of unmanaged array vs. managed array? (visual c++)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
buu - 27 Sep 2007 18:13 GMT
are there any benefits?

performance?
anonymous - 27 Sep 2007 18:26 GMT
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?
buu - 27 Sep 2007 19:13 GMT
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

> Unmanaged arrays should come witha  performance boost.  Everytime you
> reference an element in a Managed array the framework needs to do a
[quoted text clipped - 9 lines]
>>
>> performance?
anonymous - 27 Sep 2007 20:14 GMT
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;
 }
}

> I have a unmanaged array declared with:
>
[quoted text clipped - 19 lines]
> >>
> >> performance?
buu - 27 Sep 2007 23:43 GMT
it seems ok, but after that, inside the class, I have a memset(arr) command,
and I got an memory corruption error.

> You will need to convert your unmanaged array to a managed array.
> Fortunately there is a class in the System::Runtime::InteropServices
[quoted text clipped - 36 lines]
>> >>
>> >> performance?
buu - 27 Sep 2007 23:44 GMT
it seems ok, but after that, inside the class, I have a memset(arr) command,
and I got an memory corruption error.

> You will need to convert your unmanaged array to a managed array.
> Fortunately there is a class in the System::Runtime::InteropServices
[quoted text clipped - 36 lines]
>> >>
>> >> performance?
buu - 27 Sep 2007 23:44 GMT
it seems ok, but after that, inside the class, I have a memset(arr) command,
and I got an memory corruption error.

> You will need to convert your unmanaged array to a managed array.
> Fortunately there is a class in the System::Runtime::InteropServices
[quoted text clipped - 36 lines]
>> >>
>> >> performance?

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.