owner pointers
Sclytrack
idiot at hotmail.com
Sun Nov 29 02:10:27 PST 2009
Assume: no garbage collector
----------------------------
Let us say that we have two types of pointers. Owner pointers and view pointers.
owner(pointer(int))
view(pointer(int))
owner(pointer(int)) routineA()
{
owner(pointer(int)) a = malloc();
//The compiler checks that ownership is returned or passed on to
//another routine. (Possible?)
return a;
}
-------------------- //Yes 20 long "-"
void doStuffA( view(pointer(int)) param)
{
//not in charge of the deallocation.
}
void doStuffB( owner(pointer(int)) param)
{
free(param);
}
void routineB()
{
owner(pointer(int)) a = malloc();
doStuffA(a);
doStuffB(a); //Passes on ownership.
//routineB is no longer in charge of the deallocation, because of doStuffB.
}
--------------------
void usingStuff()
{
owner(pointer(int)) a = routineA();
//You are in charge of the deallocation.
free(a);
}
--------------------
More information about the Digitalmars-d
mailing list