|
From: Per W. <pw...@ia...> - 2004-01-10 12:44:06
|
The code is syntactically completely ok. However, you shouldn't take for
granted that you know what is stored on a specific location, unless you
have a document saying so.
In Windows, you could use IsBadReadPtr(ptr,size)/IsBadWritePtr(ptr,size)
to check if you have read access to the memory. Then you don't have to
hook exceptions or just loose the program because you try some fancy
memory tricks.
/Per W
On Sat, 10 Jan 2004, Daniel Glenfield wrote:
> Seconded. You are printing what's at that memory location, and it seems t=
he
> OS hasn't dealt with the value at that memory location yet.
>
> Here's a question though - can I do something like
> int* SomeMemory =3D 0x001249FF;
> printf("%d\n", SomeMemory);
>
> To print whatever is at any memory location (on the stack/heap in this ca=
se,
> I forget which starts around 0x0012~ in windows). Is this valid (dangerou=
s I
> am sure, but can I do this?).
>
> Daniel
>
>
> >From: OROSZI Bal=E1zs <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 =3D (int *)malloc(sizeof(int));
> >>*a =3D 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 fre=
ed
> >memory with zeros, while Windows does not.
> >
> >Again, the above must be considered as unpredictable, so you shouldn't c=
are
> >about freed memory (variables): they are no longer yours, they were give=
n
> >back to the OS, so you theoretically "don't want" to do anything with th=
em
> >any further.
> >
> >--
> >Greetings,
> > Bal=E1zs
> >
> >
> >
> >-------------------------------------------------------
> >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
>
>
>
> -------------------------------------------------------
> 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
>
|