🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

3 total messages Started by Jon.Cassorla Wed, 13 Mar 1996 15:04
stack variables and new constructor
#3652
Author: Jon.Cassorla
Date: Wed, 13 Mar 1996 15:04
21 lines
1646 bytes
I'm fairly new to the world of C++ so I didn't know if these questions would
be better asked in this group or in comp.lang.c++.  Anyway, here goes.

1) For a variable that is declared locally to a function of a structure 
   type, is the standard new constructor executed to allocated the 
   memory for the data structure?

2) When using "new" to allocate data space for a variable of a structure 
   type (ie no constructor defined), is the resulting memory space zero'd
   out as a standard?
-- 
Jon Cassorla 			email: Jon.Cassorla@ColumbiaSC.ATTGIS.COM
AT&T GIS Server Systems Software
3325 Platt Springs Road		phone: (803) 939-2070, VP 632-2070
Columbia, SC 29170		FAX:   (803) 939-7317
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
Re: stack variables and new constructor
#3657
Author: Paul D. DeRocco
Date: Wed, 13 Mar 1996 23:44
36 lines
2264 bytes
Jon.Cassorla wrote:
> 1) For a variable that is declared locally to a function of a 
>    structure
>    type, is the standard new constructor executed to allocated the
>    memory for the data structure?

No. You mustn't confuse "new" with "constructor". "new" allocates memory 
from the heap (and "delete" returns it). A constructor turns raw memory 
into a valid object (and a destructor turns it back into raw memory). 
Using "new" always calls a constructor if there is one (and "delete" 
always calls a destructor if there is one), but the opposite isn't true. 
If an object is static, it is allocated space by the 
compiler/linker/loader, constructed at the start of the program, and 
destroyed at the end. If an object is dynamic, it is allocated space on 
the stack, constructed when its declaration is executed, and destroyed 
when the containing block exits. Only if it is created in the heap with 
"new" does "operator new" get called.

> 2) When using "new" to allocate data space for a variable of a 
>    structure
>    type (ie no constructor defined), is the resulting memory space 
>    zero'd
>    out as a standard?

Nope, although there may be OSes that do this.

-- 

Ciao,
Paul D. DeRocco
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
Re: stack variables and new constructor
#3659
Author: Jason D. Morris
Date: Wed, 13 Mar 1996 23:49
25 lines
1732 bytes
On 13 Mar 96 15:04:23 GMT, "Jon.Cassorla"
<cassorla@casey.columbiasc.ncr.com> wrote:

>1) For a variable that is declared locally to a function of a structure 
>   type, is the standard new constructor executed to allocated the 
>   memory for the data structure?

new is an operator not a constructor.  The non-overloaded form of
operator new allocates memory in which an object can be constructed.
After the memory is allocated, the object's ctor is called to build
the object from raw memory.

>2) When using "new" to allocate data space for a variable of a structure 
>   type (ie no constructor defined), is the resulting memory space zero'd
>   out as a standard?

No.

Jason
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads