After mallocing I see ÿÿÿÿ after data...
I''m using MSVC++
I malloc out a hunk of ram, say 4 bytes and see the new uninitialized hunk of ram appear in the debugger as:
ÍÍÍÍÿÿÿÿ
What''s with that? I zero the memory and it disappears. I memcpy in a value in to those 4 bytes and now I see
abcdÿÿÿÿ
sizeof() = 4...
Whats going on? I didn''t used to see that when I used statically defined character arrays but when I use a malloc''ed hunk of ram I get this?
What does this mean?
Chris Brodie
ok dude....
when it creates the memory... it reserves a location in memory... it doesn''t do anything with it so the memory contains what ever was there before... when you zero it out it clears the memory...
when msvc displays a string it goes until it gets a NULL byte terminating the string... when you memcopied the string you probably didn''t place a NULL byte at the end... and because you overwrote the NULL bytes in the string it doesn''t see the end of the string... and it keeps going.... try making your string one more byte in length and then zero it out... or otherwise make sure a NULL is placed at the end
Great Milenko
when it creates the memory... it reserves a location in memory... it doesn''t do anything with it so the memory contains what ever was there before... when you zero it out it clears the memory...
when msvc displays a string it goes until it gets a NULL byte terminating the string... when you memcopied the string you probably didn''t place a NULL byte at the end... and because you overwrote the NULL bytes in the string it doesn''t see the end of the string... and it keeps going.... try making your string one more byte in length and then zero it out... or otherwise make sure a NULL is placed at the end
Great Milenko
Words Of Wisdom:
"Never Stick A Pretzel In Your Butt It Might Break Off In There."
http://www.crosswinds.net/~milenko
http://www.crosswinds.net/~pirotech
The Great Milenko"Don't stick a pretzel up your ass, it might get stuck in there.""Computer Programming is findding the right wrench to hammer in the correct screw."
If you know that the place you are copying from is a string already you maky your array the size of the string +1 and memcpy size of string+1 Or as previous post said just put a ''/0'' character in the last memory location for the string.
-----------------------------------------------All messages are of my own personal opinion and not meant to offend. But if they do - tough :)Neuro.
quote: Original post by Neuro
If you know that the place you are copying from is a string already you maky your array the size of the string +1 and memcpy size of string+1 Or as previous post said just put a ''/0'' character in the last memory location for the string.
It''s not ''/0'' it''s ''\0''
/. Muzzafarath
Mad House Software
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
Sorry, your correct. That what comes to having 3 unix shells open on your desktop.
it is ''\0'' just like it is ''\n'' and ''\\'' and so on...
Apart from that error, everything else is correct.
it is ''\0'' just like it is ''\n'' and ''\\'' and so on...
Apart from that error, everything else is correct.
-----------------------------------------------All messages are of my own personal opinion and not meant to offend. But if they do - tough :)Neuro.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement