Proposal to eliminate `activenew' keyword in favour of placement new

Jonathan Poole

A postscript version of this whole document is available here

The latex source is available here

Proposal is to get rid of the activenew keyword and instead use `placement new'. Getting rid of unneceesary additions is obviously good in and of itself. The use of placement new is not arbitrary though, as the allocation information can indeed be seen as stating where the object is to be placed.

Combined with the proposal to change the way asynchronous functions are called, (see separate proposal) it should allow libraries created using UC++ to be used by standard C++ programs, as no additional syntax is necessary at class use time.

Declaring an active object is then as follows

   UCPPClass *ac = new(Active("stanley")) UCPPClass(constructor args);

and a passive object would be declared as

   ActiveClass *ac = new ActiveClass(constructor args);

This requires just the definition of a placement new operator for UC++ classes as follows:

  void* operator new(size_t sz, _UCPPAllocator allocator = _DefaultAllocator)
// do the stuff setting up the proxy etc as appropriate.      
      return ::operator new(sz) ;

G++ version 2.6.3 supports this syntax, so it is implementable immediately. It gives us extra flexibility as Allocators become first class objects and we can build different constructors for them to allow different forms of allocation information to be given. Thus if we have a constructor from strings to Allocators we can use the simple form:

   UCPPClass *ac = new("") UCPPClass(constructor args);


placement new will be called when we use explicit new...what about when we declare objects inline? What can we do about this? Use default constructor that fails?

There are many issues about the order things happen: the object life cycle, with allocation, construction etc. This puts creating proxies at the allocation stage instead of the constructor stage.

Jonathan Poole
Wed Aug 2 17:53:41 BST 1995