Jump to content
  • Advertisement
Sign in to follow this  
V-man

C# arrays

This topic is 3396 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am tested out c#. It seems as if in comparison to C and C++, you can't declare an array on the stack like this int array[100]; I have to do this instead int[] array; array=new int[100]; Why does it require dynamic memory allocation? [Edited by - V-man on May 3, 2009 3:22:56 PM]

Share this post


Link to post
Share on other sites
Advertisement
In C# arrays are reference types, they inherit from the base class Array, and like all reference types they are allocated on the heap rather than the stack.

Share this post


Link to post
Share on other sites
Heap allocation doesn't have to be quite as bad in C# as C++ however. Modern managed languages can take advantage of a number of optimisations which can make dynamic allocation relatively cheap and garbage collection relatively quick for short lived objects.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!