Message: Re: Using shared_ptr (from the boost library) Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

None Re: Using shared_ptr (from the boost library) 

Forum: Installation and Configuration
Re: None Using shared_ptr (from the boost library)
Re: Question Re: Using shared_ptr (from the boost library) (Gabriele Cosmo)
Date: 21 Nov, 2007
From: Peter Niessen <niessen@ifh.de>

On Wed, 21 Nov 2007, Gabriele Cosmo wrote:

> *** Discussion title: Installation and Configuration
> Email replies to PublicHyperNews@slac.stanford.edu must include:
>   In-Reply-To: <"/installconfig/1017/1"@geant4-hn.slac.stanford.edu>
>   Subject: ...change this to be about your reply.
> 
> Hi Peter,
> 
> > it seems that in a G4 application, one always says "new" but never tidies up
> 
> can you please better elaborate this statement you make ?
> 
> Of course, in a user application one is free to do whatever for memory management
> (also use Boost in case), but for what concerns the Geant4 kernel, memory dynamically
> allocated is tied up, of course, otherwise you won't be able to simulate too many events
> I'm afraid .....

Ciao Gabriele,

thank you for the quick reply!

In my application, I usually do a lot of "new", espescially in the
detector construction: New Elements, new Material Properties, new
volumes, etc.

Then, before returning the physical world volume, I lose all these
pointers, as they go out of scope:

G4VPhysicalVolume *MyDetector:Construct () {

	G4MaterialPropertiesTable *mpt = new G4MaterialPropertiesTable ();

	// fill the world with some material with properties
	my_world_log = new G4LogicalVolume (..., material_with_mpt, ...);

	G4VPhysicalVolume *my_world = new G4PVPlacement (..., my_world_log, ...);

	// should we tidy up here?
	delete mpt; // bad idea! When G4 accesses the mpt passed to
	// my_world, it finds nothing and will core dump.

	return my_world;

	// here, I've lost the pointers to the mpt, my_world, ...
	// I've forfeited all opportunity to tidy up.

}

The prime motivation for me to do this is to be able to tidy up things
in case of exceptions (try { ... } catch) (e.g. when there's a syntax
error in a steering file, some database connection fails, ...)

Thanks again for your attention,

Peter.

> 
> Gabriele
> 
> ++ No Boost goodies are used within Geant4...
> 

Peter Niessen
Bartol Research Institute
University of Delaware
Newark, DE 19716-4793
U.S. of America

Tel (+1)302/831-8700
Fax (+1)302/831-1843
e-mail niessen@ifh.de
www http://www.ifh.de/~niessen

Aber icerec, der alte Knochen, war ja schon immer die H-Milch unter
den Metaprojekten, also koennte sim2.0+rec1.5.9 ne lange Ehe werden.

S. Klepser, August 2007

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 More: Re: Using shared_ptr (from the boost library)   (Gabriele Cosmo - 21 Nov, 2007)
(_ None: Re: Using shared_ptr (from the boost library)   (Peter Niessen - 21 Nov, 2007)
 Add Message Add Message
to: "Re: Using shared_ptr (from the boost library)"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews


[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]