digitalmars.D - owner pointers
- Sclytrack (36/36) Nov 29 2009 Assume: no garbage collector
- Denis Koroskin (2/40) Nov 29 2009 What's the point of this post?
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); } --------------------
Nov 29 2009
On Sun, 29 Nov 2009 13:10:27 +0300, Sclytrack <idiot 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?
Nov 29 2009