wierd array problem

Started by
0 comments, last by Aldenar 19 years, 5 months ago
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.
Advertisement
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.

This topic is closed to new replies.

Advertisement