Sign in to follow this  
corrington_j

wierd array problem

Recommended Posts

I am using c++ and had an array that was not dynammic, and when i made it dynamic the code sudenly started breaking because of going out of bounds on the array. I noticed it would have been going out of bounds before i made it dynammic, but the program never crashed. I am just curious why it is crashing when the array is allocated dynamically, and not crashing when it is allocated statically.

Share this post


Link to post
Share on other sites
When you are writing outside the range of a static array, chances are that you'll overwrite a variable of your own program. So there's a chance that you would have experienced an unexpected behavior from your application.

With arrays that are dynamically allocated, you don't know what memory zone you'll get when calling new. So when going out of bounds, you could hit padding, memory management structures, another block of memory that you allocated or it could even try to write to a block that has not yet been allocated. There are a lot more chances that it will crash.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this