Article View: net.lang.c++
Article #177Initializing objects on the heap
From: sher
Date: Thu, 01 May 1986 01:34
Date: Thu, 01 May 1986 01:34
23 lines
1421 bytes
1421 bytes
Right now I am writing in c++ a program to manipulate a linked list. This means that proceedures and function often want to create objects on the heap since it is a bad idea to return objects on the stack. Also it is a good idea to initialize all objects you create. The only way I know to put an initialized object onto the heap is: foo * fp = new foo; foo f ( init ); *fp = init; If f is a large object with many pieces this is a very wasteful proceedure since this involves copying f into the space of fp after going to the work of creating and allocating f. Is there a better way of doing this? I know it can be done by creating a function that takes fp and initializes it with init but I find this inelegant. Why have constructors if they have to always be bypassed? -- -David Sher sher@rochester seismo!rochester!sher
Technical Details
Message-ID:
<17755@rochester.ARPA>Path:
arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!bellcore!decvax!decwrl!pyramid!pesnta!amd!amdcad!lll-crg!seismo!rochester!sherShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!bellcore!decvax!decwrl!pyramid!pesnta!amd!amdcad!lll-crg!seismo!rochester!sher From: sher@rochester.UUCP Newsgroups: net.lang.c++ Subject: Initializing objects on the heap Message-ID: <17755@rochester.ARPA> Date: Wed, 30-Apr-86 21:34:00 EDT Article-I.D.: rocheste.17755 Posted: Wed Apr 30 21:34:00 1986 Date-Received: Sat, 3-May-86 18:07:36 EDT Reply-To: sher@rochester.UUCP (David Sher) Organization: U of Rochester, CS Dept Lines: 23 Keywords: heap, new