brad211987
10-06-2009, 01:01 AM
Still don't have the memory model soundly in my head apparently. I am creating string as an array of characters in a C++ program:
char* myString = new char[8];
after this call, looking in a debugger shows that the array is padded with 8 encoded \253. This brings the length of my string to 16, can someone explain what the heck is going on here?
Here is a code snippet in question: it is a simple insert function, snipped out all but the first part where my issue is.
void MyString::insert(int pos1, const char* s)
{
char* org = storedValue;
int orgLength = strlen(org);
int insLength = strlen(s);
storedValue = new char[8];
int test = strlen(storedValue);
The 8 is a hard coded value for now, but it should be length of original string plus length of variable s, which for my test data happend to be 8. Anyway, at the end of this, the variable test gets the value of 16......why? Later I am adding characters to this new array(8 of them) and the extra padding creates strange characters on the final output.
**EDIT**
increasing my hard coded value to 16 results in an ending length of 24, so it's adding 8 bytes.....
**EDIT 2**
This seems to have something to do with windows vista and or eclipse....and/or MinGW. Copying the code into a cygwin installation seems to make the problem go away and start functioning normally.
char* myString = new char[8];
after this call, looking in a debugger shows that the array is padded with 8 encoded \253. This brings the length of my string to 16, can someone explain what the heck is going on here?
Here is a code snippet in question: it is a simple insert function, snipped out all but the first part where my issue is.
void MyString::insert(int pos1, const char* s)
{
char* org = storedValue;
int orgLength = strlen(org);
int insLength = strlen(s);
storedValue = new char[8];
int test = strlen(storedValue);
The 8 is a hard coded value for now, but it should be length of original string plus length of variable s, which for my test data happend to be 8. Anyway, at the end of this, the variable test gets the value of 16......why? Later I am adding characters to this new array(8 of them) and the extra padding creates strange characters on the final output.
**EDIT**
increasing my hard coded value to 16 results in an ending length of 24, so it's adding 8 bytes.....
**EDIT 2**
This seems to have something to do with windows vista and or eclipse....and/or MinGW. Copying the code into a cygwin installation seems to make the problem go away and start functioning normally.