owner pointers
Denis Koroskin
2korden at gmail.com
Sun Nov 29 04:14:45 PST 2009
On Sun, 29 Nov 2009 13:10:27 +0300, Sclytrack <idiot at hotmail.com> wrote:
> 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);
> }
>
> --------------------
>
>
>
>
>
What's the point of this post?
More information about the Digitalmars-d
mailing list