[lug] new operator in C++
LittleViggy at alum.manhattan.edu
LittleViggy at alum.manhattan.edu
Mon Apr 29 14:33:24 MDT 2002
I just tuned into this message, so if this has been answered before, I
apologize.
You are guarenteed NOTHING in C++ as far as memory is concerned. There are no
standards that say memory is to be initialized when allocated, and cleared when
freed.
If this is something you'd like, you can certainly overload the "new" operator
to call the base level operator, then fill in the chunk of memory with 0's (or
whatever).
On another note, some compilers will do exactly this, in debug mode only. For
example, Microsoft's Visual C++ fills in "new'd" memory with 0xcccccccc; and
fills in deleted memory with 0xdddddddd; but **ONLY** in debug mode. This way,
you can easily see if you are accessing memory after it has been deleted.
Viggy
Peter Hutnick wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Saturday 27 April 2002 01:57 pm, Stephen Queen wrote:
> > In using the new operator in C++ I cannot find whether it is guaranteed
> > to initialize the new memory to zero or not. In playing with it, it
> > looks like it does, but that might be coincidence. Does anyone know a
> > source of information on the net regarding this? Another question
> > regarding sources of information on C++. man has section 3 which is a
> > good source of information for regular C. Does anyone know of anything
> > like that for C++? It sure would come in handy now and
then.
-------------------------------------------------------------
This message was sent from Peak to Peak Internet.
DSL - V.90 modems - Web Hosting and Business connectivity
Please visit! http://www.peakpeak.com
(888)-600-PEAK
-------------------------------------------------------------
More information about the LUG
mailing list