Dynamic Array created too big

I am using
char* stringl = new char[templength];
to create a dynamic array with the size templength
From debugging in visual studio, it quite clearly shows that templength is 27, however the array that is created contains 33 characters (meaningless characters)

When i come to write characters to the array and display its contents, i'm consistantly left with jumbled characters after what i want to display,
Any insight as to why this is happening? =/
Ugh, found out that this seems to only happen in debug versions, in a release version, this no longer occurs >_>
Any ideas why?
...debugging in VISUAL STUDIO...


Yeah, I have some thoughts on why something like that might happen. Bill Gates can probably fill in the rest of the details for you. :)
How do you know it has 33 chars? If you've asked for 27, you are given 27.

Microsoft's debug heap provides guard bytes on each allocation so it can help you find heap errors. It's a standard technique there to help you. It is not an error.
Its fine now, ive been able to place it into a string and resize the string, but still...
In debugger, by vewing the contents of the array, it actually does contain 33 characters, random ones that i then define, but the extra ones remain random
As kbw said, they aren't random characters. They're there for debug purposes. This is why debug builds are physically larger than release builds. It should have zero impact on your code though.
Topic archived. No new replies allowed.