[lug] new operator in C++

Tkil tkil at scrye.com
Sat Apr 27 19:50:18 MDT 2002


>>>>> "DS" == D Stimits <stimits at idcomm.com> writes:

DS> The indirect memory being pointed to is no longer accessible after
DS> the free. The pointer itself still exists, just not what it points
DS> at.

let me try to make it clear here that i do, in fact, understand
pointers.  :)

what confuses me is that it appears that the allocator actually gives
the memory back to the system, since i segv when i try to access it
after "delete".

in this context of a program which relies on a library to do most of
this management, that library only grabbing chunks from the operating
system and then giving them back when done, i'd expect the library to
maintain a list of free slots/blocks that it can give out on demand.
in this case, since i'm continuously doing "new" and "delete", i
expected to get the same chunk of memory each time -- and i do (at
least in the virtual sense: printing out "pi" itself shows that the
address, as seen by the program, didn't change).

so, the things that surprised me:

1. the allocator gave the memory all the way back to the OS (which is
   what i thought had to happen before i'd get a SEGV).

2. that something else is scribbling consistently into that memory.
   i suppose it's something in the iostream classes, but i'm surprised
   that anything in there is doing free store manipulation.

not that it really matters.  just the usual "hm, i didn't know it
worked that way" type over-analysis.  as someone pointed out, just
initialize the damned thing and be done with it.  :)

t.



More information about the LUG mailing list