$new

$new is like new except that it registers the object in the current CSpace in thread local storage.

For example given the class


$class+ X isa IObject
{
public:
    X();
    X(int a, int b);
private:
    [ implementation ]
};

the following code can be used to create objects in the CSpace


X* x1 = $new X;
X* x2 = $new X(1,2);

The lifetime of these objects is managed by the CSpace. If they are not reachable from the GC roots then they will be deleted when a garbage collection is performed.

There are two requirement to using $new

IObjects that aren't registered in the CSpace

When a class implements IObject it's not mandatory for it to be registered with a CSpace (nor even to be heap allocated). It is permissible for it to be a member of another class, a global variable, a frame variable etc.


$class+ Y isa IObject
{
    X x;            // member of another class
};

void foo()
{
    X x;            // declared on frame

    X* px = new X;  // heap allocated but not registered in a CSpace
    delete px;
}