Welcome to RenEvo Sign in | Join | Help
in
Home IRC Wiisis C&C FarCry Blogs Forums Photos Downloads

Problem with dynamic memory

Last post 12-28-2006, 10:31 AM by Jary. 2 replies.
Sort Posts: Previous Next
  •  12-26-2006, 6:04 PM 537

    Problem with dynamic memory

    Hi all,

     Merry X-mas, good holidays to all.

     I have a little problem with dynamic memory.

    I want to get 4 chars this way:

    char *reason = new char [4];

     

    What is weird is that the debugger tells me this:

    +  reason 0x009851b8 "ÍÍÍÍýýýý««««««««îþîþîþîþ" char *

    then, when I sent 4 chars in reason, they are still more: (using

    buffer.copy(reason,buffer.size());

     

    I get:

    Testýýýý««««««««îþîþîþîþ

    but I should only get Test. I don't wish to add '\0' at the end, that's the purpose of my pointer.

    Thanks to anyone who can help me. (Hope it's clear, cause it's 2 am here, i'm a bit tired).

     

    Thanks all

  •  12-28-2006, 9:04 AM 552 in reply to 537

    Re: Problem with dynamic memory

    Your debugger is just treating pointers to char as a character string. So the debugger is just reading characters until it reaches a null character, or until it's read a certain amount. When you allocate any memory (whether it's on the heap or the stack) you can't determine what the value of that memory will be. So for both those reasons, that's why your debugger is saying you've got those random characters at that memory location.
  •  12-28-2006, 10:31 AM 556 in reply to 552

    Re: Problem with dynamic memory

    Thanks for help.
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems