|
From: Daniel G. <sp...@ho...> - 2004-01-10 10:24:36
|
Seconded. You are printing what's at that memory location, and it seems the
OS hasn't dealt with the value at that memory location yet.
Here's a question though - can I do something like
int* SomeMemory = 0x001249FF;
printf("%d\n", SomeMemory);
To print whatever is at any memory location (on the stack/heap in this case,
I forget which starts around 0x0012~ in windows). Is this valid (dangerous I
am sure, but can I do this?).
Daniel
>From: OROSZI Balázs <or...@vp...>
>To: dev...@li...
>Subject: Re: [Dev-C++] malloc and free
>Date: Sat, 10 Jan 2004 11:09:48 +0100
>
>Siva Chandra wrote:
>>I used the follwoing piece of code as a test:
>>
>>int *a;
>>a = (int *)malloc(sizeof(int));
>>*a = 5;
>>free(a);
>>printf("%d\n", *a);
>>
>>This prints 0 in the linux environment and 5 in the
>>windows environment!!
>>
>>does anyone out there know whats happening??
>>the same happens with new and delete!!
>
>You should take the above printf() as "unpredictable". After you free or
>delete some allocated memory, it is the operating system's task to do
>whatever it want's with it. It seems, that Linux automatically fills freed
>memory with zeros, while Windows does not.
>
>Again, the above must be considered as unpredictable, so you shouldn't care
>about freed memory (variables): they are no longer yours, they were given
>back to the OS, so you theoretically "don't want" to do anything with them
>any further.
>
>--
>Greetings,
> Balázs
>
>
>
>-------------------------------------------------------
>This SF.net email is sponsored by: Perforce Software.
>Perforce is the Fast Software Configuration Management System offering
>advanced branching capabilities and atomic changes on 50+ platforms.
>Free Eval! http://www.perforce.com/perforce/loadprog.html
>_______________________________________________
>Dev-cpp-users mailing list
>Dev...@li...
>TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
_________________________________________________________________
Stay in touch with absent friends - get MSN Messenger
http://www.msn.co.uk/messenger
|