📄 refcnt.mal
字号:
function tmp():void; d:= bbp.getRefCount(); dl:=bbp.getLRefCount(); dn:= bbp.getNames(); io.print(dn,d,dl);end tmp;#NOTE: the reference counter of bat(name) is during insertion# into bat(b) correctly increased#PROC addBAT(bat b,str name) : void {# VAR add := new(int,int);# add.rename(name);# b.insert(name,add);#}function addBAT(b:bat[:str,:bat],name:str):void; add:= bat.new(:int,:int); bat.setName(add,name); bat.insert(b,name,add);end addBAT;###BUG: bat(name) will not be deleted in the garbage collection## because the delete doesn't decrease the reference counter#PROC delBAT(bat b,str name) : void {# b.delete(name);#}function delBAT(b:bat[:any_1,:any_2],name:str):void; bat.delete(b,name);end delBAT;##PROC createBAT(str name) : bat[int,int] {# VAR res := new(int,int);# res.rename(name);# RETURN res;#}#NOTE we can not return (yet) a (:bat,:bat[:int,:int])#into a multiplex. This means that the BATs created# are immediately garbage collected when leaving the#function. A hack would be to provide explicit incref/decreffunction createBAT(name:str):bat; res:= bat.new(:int,:int); bat.setName(res,name); i:= calc.getBATidentifier(res); return i;end createBAT;##tmp();user.tmp();##{##VAR top := new(str,bat);#top.rename("top");top := bat.new(:str,:bat);bat.setName(top,"top");##addBAT(top,"one");#addBAT(top,"two");user.addBAT(top,"one");user.tmp();user.addBAT(top,"two");#tmp();user.tmp();##delBAT(top,"one");user.delBAT(top,"one");io.print("one droppped");#tmp();user.tmp();##VAR i := new(oid,str);m:= bat.new(:oid,:str);#i.insert(oid(10),"ten");bat.insert(m,10:oid,"ten");#i.insert(oid(20),"twenty");bat.insert(m,20:oid,"twenty");#VAR res := [createBAT](i);io.print("do multiplex");r:bat[:oid,:bat]:= optimizer.multiplex("user","createBAT",m);io.print(r);#tmp();io.print("done multiplex");##top := nil;#res := nil;##}###BUGS:# in M5 this bug does not appear, because there is one reference# returned from createBAT.##- bat("one") still exists, due to not decreasing the reference counter## at the delete from bat("top")##- bat("ten") and bat("twenty") still exist, due to creation during multiplex## operation (?)# moreover, due to multiplex code inlining the reference count of "twenty" is 2# instead of the initial expected 1.#tmp();#quit();clients.quit();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -