| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> c/c++ >> C++ yin yong ji shu de zhi neng zhi zhen you xiao hui shou fang fa

C++ yin yong ji shu de zhi neng zhi zhen you xiao hui shou fang fa

2008-06-01 02:09:43 编辑來源:互联网 评论
 
 
 
本文为【C++引用计数的智能指针有效回收方法】的拼音翻译版
  yin yong ji shu zhi zhen shi fou neng you xiao di hui shou , dui xi tong yi wai guan ji zhi hou shu ju de hui fu lai shuo zhi guan chong yao , yao hai shi yao bi mian dui xiang fu zhi 。
  zen yang cong zai nan xing gu zhang zhong , hui fu yi ge chang qi yun xing 、 xi tong ji de hou tai shou hu jin cheng huo zhe fu wu , zai ru jin de ruan jian she ji guo cheng zhong , yi cheng wei le yi ge chong yao de kao lv yin su 。 dang zhe xie ruan jian shi you C++ yu yan bian cheng , bing shi yong le yin yong ji shu de zhi neng zhi zhen shi , na me , zhi neng zhi zhen de you xiao hui shou , dui xi tong shi fou ju you ke shen suo ji de hui fu neng li 、 shen zhi zheng que di ji xu wei wan cheng de cao zuo lai shuo , dou xian de zhi guan chong yao 。
  zai ben wen zhong , miao shu le yi zhong fang fa , ke cong guan ji zhi hou de ruan jian hui fu zhong , you xiao di hui shou yin yong ji shu zhi zhen , er qie ci fang fa zai nei cun zhan yong fang mian ye fei chang gao xiao , zhe zhong fang fa de yao hai zai yu bi mian dui xiang fu zhi , er dui xiang fu zhi tong chang shi you C++ zhong zhi zhen yin yong de chuan xing hua yu fan chuan xing hua zhe zhong chuan tong ji shu chan sheng de 。 dang cong cun dang wen jian zhong fan chuan xing hua shi , ben fang fa shi yong le biao ji (tag) lai wei yi di shi bie zhi zhen dui xiang , qie zai xi tong hui fu shi you yi ge dui xiang huan cun lai bao cun zhi zhen yin yong 。
  ben wen yi yi ge ji yu shi jian de shang ye shi shi zuo ye tiao du xi tong lai jin xing yan shi , qi tong chang you da xing shi chang zi xun gong si shi yong , tian tian dou hui zai ji qun gong zuo zhan shang chu li shu bu sheng shu de ji suan ren wu 。
  wei shen me xu duo C++ ruan jian xiang mu hui shi yong zi dong nei cun zhi li ji shu ne , yin wei ta you yi xia hao chu :
  ² dai ma an quan xing 。 bi mian le tai zao shi fang yi ge dui xiang suo dai lai de feng xian 。
  ² dai ma zheng que xing 。 bi mian le wang ji shi fang wei shi yong nei cun suo dai lai de feng xian 。
  ² dai ma mo kuai xing 。 dai ma zhong bu zai xu yao dian zhui zhe yu cheng xu wu guan de bao ji dai ma 。
  ² bian cheng jian dan xing 。 xian zai ke jia ding yi zhong wu xian nei cun de ji suan mo shi 。
  ² bian cheng gao xiao xing 。 cheng xu yuan bu zai dan xin nei cun zhi li wen ti 。
  yin yong ji shu zhi neng zhi zhen , you shi ye cheng wei “ ji shu ti shu yu ”, shi yi zhong sheng ming qi shou guan de dui xiang , qi dui yin yong ta de shu liang , you yi ge nei bu de ji shu qi 。 dang nei bu yin yong ji shu wei ling shi , zhe xie dui xiang hui zi dong xiao hui zi shen , zhe shi yi zhong fei chang you yong de ji shu , yi yun yong zai xu duo C++ ruan jian chan pin xiang mu zhong , yin wei jian dan yi xing , qie wu xu dui yu yan huo bian yi qi jin xing ren he kuo zhan 。
  yin yong ji shu zhi neng zhi zhen neng jin yi bu ding yi wei yi ti shi huo fen li shi , yi ti shi zhi neng zhi zhen ba yin yong ji shu fang zai zi shen nei , er fen li shi zhi neng zhi zhen ze ba yin yong ji shu fang zai dui xiang zhi wai 。 zai ben wen zhong , shi yong de shi fen li shi zhi neng zhi zhen fang an , zhe xu yao zai fang wen shi ji dui xiang zhi zhen zhi qian , zai zhi neng zhi zhen mo ban dui xiang zhong chong zai -> huo * cao zuo fu , cong ben zhi shang lai shuo , zhe ye shi dai li (PRoxy) she ji mo shi de yi ge te li 。
  jiu mu qian lai shuo , huan mei you yi zhong fang an yi gao xiao li yong nei cun de fang shi miao shu le zen yang hui fu zhi neng zhi zhen , er chuan tong de C++ dui xiang chuan xing yu fan chuan xing hua fang fa , hui dao zhi nei cun di xiao , yin wei dang yi ge fan chuan xing hua de dui xiang peng dao yi ge dui ta de yin yong shi , zong shi hui chuang jian yi ge xin dui xiang , zai zui huai de qing kuang xia , zhe hui ba yi ge hui fu hou de shou hu jin cheng de nei cun xiao hao liang , tui dao yi ge wu fa jie shou de gao du , zhi shi ta wu fa ji xu yun xing xia qu 。
  wen ti de yin chu
  chuan tong dui xiang de chuan xing yu fan chuan xing hua fang an , ye neng shi xian zhi neng zhi zhen , zhi bu guo zai nei cun shang bi jiao di xiao er yi 。 zai zhe xie chuan tong fang an zhong , dang yi ge dui xiang chuan xing hua shi , dui xiang nei de cheng yuan zhi zhen bei jie yin yong , ta de nei rong yu dui xiang yi qi “ chuan xing ” jin cun dang wen jian zhong 。 zhe zhong fang fa de wen ti zai yu , dang fan chuan xing hua shi , cheng yuan zhi zhen hui zai ci gou zao , qie shi mei ge hui fu de dui xiang dou hui zhe yang 。
  xia mian yi ji yu shi jian de zuo ye tiao du xi tong lai jin xing jiang jie , zuo ye ding yi zai CJobDef dui xiang zhong , qi bao han le zuo ye de jing tai shu xing , ru ta zhi xing de ming ling 、 gong zuo mu lu 、 ji zuo ye zhi xing shi de yong hu ID。 er zuo ye ding yi de yun xing shi li ze bao zhuang zai CJobInst dui xiang zhong , qi bao han le yi xie yu shi li you guan de shu xing , ru ta de jin cheng ID、 zhi xing shen shu 、 ji yun xing li shi ji lu 。 zai lei ceng ci shang , mei ge CJobInst dui xiang dou bao han le yi ge cheng yuan , qi yin yong dao chu fa zhe ci zuo ye shi li de yuan shi CJobDef dui xiang 。
  tu 1 shi ruan jian ting zhi yun xing zhi qian de xi tong , yun xing shi CJobInst dui xiang de duo ge shi li ke neng hui yin yong zhi tong yi ge CJobDef dui xiang 。 zai ruan jian ting zhi ji hui fu hou , chuan tong chuan xing hua dui xiang hui fu fang fa , hui dao zhi wei mei ge yun xing de CJobInst dui xiang , dou chuang jian yi ge CJobDef dui xiang , ru tu 2 zhong suo shi 。
C++引用计数的智能指针有效回收方法

  tu 1: hui fu zhi qian de dui xiang tu
C++引用计数的智能指针有效回收方法

  tu 2: nei cun di xiao hui fu zhi hou de dui xiang tu
  zhe zhong qing kuang fa sheng zai chuan tong de C++ lei dui xiang zhong zhi zhen cheng yuan chuan xing hua yu fan chuan xing hua shi , li 1, shi yi duan dai you chong zai >> yu << cao zuo fu , chuan xing ji fan chuan xing hua CJobInst yu CJobDef lei zhi zhen de CArchive lei dai ma , ye zheng shi le zhe dian 。
  li 1:
  
  yi xia shi yin yong pian duan :
  class CJobDef
  {
  friend CArchive & Operator >> (CArchive &ar, CJobDef *def)
  {
  ar >> def->command;
  }
  friend CArchive & operator << (CArchive &ar, CjobDef *def)
  {
  ar << def->command;
  }
  private:
  std::string command;
  };
  class CJobInst
  {
  friend CArchive & operator >> (CArchive &ar, CJobInst *inst)
  {
  inst->m_def = new CJobDef;
  ar >> inst->m_def;
  }
  friend CArchive & operator << (CArchive &ar, const CJobInst *inst)
  {
  ar << inst->m_def;
  }
  private:
  CJobDef *m_def;
  };
  zai CJobInst zhong chuan xing hua CJobDef de si you cheng yuan m_def she ji dao tiao yong CArchive lei zhong shi dang de << cao zuo fu , chong zai de << cao zuo fu tong guo ba dui xiang shu xing chuan xing hua jin yi ge yong jiu de cun dang wen jian , lai shi xian dui CJobDef zhi zhen de chuan xing hua ; fan chuan xing hua CJobDef zhi zhen she ji dao gou zao yi ge xin de dui xiang , bing tiao yong >> cao zuo fu cong cun dang wen jian zhong geng xin shu xing 。
  jie jue fang an
  yin yong ji shu zhi neng zhi zhen shi you ji xu zi CReferable lei yi ge dui xiang shi xian de , qi bao han le yi ge si you yin yong ji shu qi ji yong yu xiu gai qi zhi de increaseReferenceCount() yu decreaseReferenceCount() fang fa , er xiang ying de Ref mo ban lei , tong guo ->、*、= cao zuo fu chong zai , ye shi xian le fang wen ci dui xiang ji dui sheng ming qi de zhi li 。Ref mo ban dui zhi neng zhi zhen de fu zhi cao zuo , hui di zeng dui xiang de yin yong ji shu , er ta de xi gou han shu hui di jian ji shu 。 zhi neng zhi zhen zhong de dui xiang zhi dang ta de yin yong ji shu wei ling shi bei xiao hui 。 zai shang mian de zuo ye tiao du xi tong zhong ,CJobDef dui xiang bei bao zhuang zai yi ge CJobDefPtr lei xing zhong , qi you yi xia yu ju ding yi :
  
  yi xia shi yin yong pian duan :
  typedef Ref<CJobDef> CJobDefPtr;
  zhe ge CJobDefPtr lei xing , zheng shi lei CScheduler suo yong dao de lei xing 。 dang yong hu ti jiao yi ge zuo ye dao shi jian zuo ye tiao du qi shi , hui chan sheng yi ge CJobDefPtr lei xing xin de dui xiang , qie hui fu yu ta CJobDef dui xiang ; ci hou , dang zuo ye shi li chuang jian shi , ye zheng shi zhe ge CJobDefPtr lei xing fu yu gei le shi li 。 tu 3 yan shi le lei CScheduler shi yong de CJobDefPtr lei xing 。
C++引用计数的智能指针有效回收方法

  tu 3: zuo ye ding yi lei guan xi tu
  zai CJobDefPtr lei zhong , fu zhi = cao zuo fu di zeng le CJobDef dui xiang CReferable ji lei zhong de yin yong ji shu , er delete cao zuo fu di jian le zhe ge yin yong ji shu 。 bao zhuang zai CJobDefPtr dui xiang zhong de CJobDef dui xiang bu hui bei xiao hui , zhi dao ta de yin yong ji shu wei ling , zhe ye shuo ming le zai xi tong zhong , mei you qi ta ren he dui xiang yin yong CJobDef dui xiang , ta ke yi an quan di bei xiao hui le 。
  zai ci ti xing , cong zuo ye zhong chuang jian de zuo ye shi li , bei bao zhuang zai yi ge CJobInst lei zhong 。 yu CJobDef yi yang , lei CScheduler zhi zhi dao ta dui ying ban ben de zhi neng zhi zhen CJobInstPtr, er ci dui xiang de shi li ye hui yi zhi bao chi dao mei you dui ta de yin yong wei zhi 。
  ling wai , zai xi tong zhong , huan bao kuo le ling wai san ge te xing , yi bian shi tiao du xi tong ke gao xiao di hui fu :
  ² lei CReferable zeng jia le yi ge tag shu xing , yi wei yi di shi bie mei ge chuang jian de zhi zhen shi li , tong shi you yi ge getTag() fang fa ke yong yu fang wen ci shu xing 。
  ² Ref mo ban lei zai cheng wei CReferableCache de quan ju dui xiang huan cun zhong zhi li ta de dui xiang , ci quan ju dui xiang huan cun ke you qi ta zhi neng zhi zhen dui xiang fang wen 。
  ² Ref mo ban lei tian jia le yi ge impersonate() fang fa , qi da ying yi ge zhi neng zhi zhen yi gei ding de tag zhuan huan wei ling yi ge zhi neng zhi zhen 。
  dang yi ge xin de CJobDefPtr huo CJobInstPtr bei chuang jian shi , zai CReferable ji lei gou zao han shu zhong , hui fen pei gei dui xiang wei yi de yi ge tag。 zhe ge tag ke you ji zhong fang shi chan sheng , dan ren yi zhong fang shi dou bi xu bao zheng zai mei ci ruan jian yun xing shi , dou hui you yi ge wei yi de ID。 yi ge jian dan de fang an shi shi yong yi ge jing tai 、 quan ju de ji shu qi dui xiang , qi zai cun dang wen jian zhong cun chu le shang yi ci chan sheng de ID, you ci ke bao zheng shen zhi zai you duo ge ruan jian shi li yun xing de tiao jian xia , dou neng dan tiao bu chong fu di di zeng ci ID。
  fen pei gei zhi neng zhi zhen de tag, wei yi di biao shi chu yi ge zhi zhen , er ba ci tag cun ru yi ge cun dang wen jian jiu shi dui xiang chuan xing hua guo cheng de ze ren le 。 dui xiang de chuan xing hua guo cheng , ke tong guo CReferable ji lei de getTag() fang fa , lai fang wen ci tag, jie xia lai , dui xiang de fan chuan xing hua guo cheng shi yong ci tag, zai ruan jian hui fu shi , lai chong jian zheng que de dui xiang zhi zhen shi li yin yong 。 xia mian shi fan chuan xing hua guo cheng bi xu zhi xing de bu zhou :
  ² cong cun dang wen jian zhong hui fu tag。
  ² cong tag biao shi de cun dang wen jian zhong , hui fu dui xiang shu xing 。
  ² yi ci tag wei jie tiao yong impersonate() fang fa , hui fu zheng que de zhi zhen dui xiang de yin yong 。
  Impersonate() hui dui shi fou yi ge tag suo yin le zai quan ju CReferableCache dui xiang ji zhong de yi ge dui xiang jin xing jian cha , jia ru wei zhao dao ci tag xiang ying de dui xiang , na me ci dui xiang hui tian jia dao CReferableCache zhong , bing yong ci tag zuo wei ta de suo yin zhi 。 ran er , jia ru yi ge dui xiang yi jing cun zai yu quan ju CReferableCache dui xiang ji zhong , tong guo yi xin yin yong lai tiao yong set() fang fa , ni ke yi she qi lao yin yong , qie wu guan de dui xiang fu zhi cao zuo ye hui zi dong bei shan chu 。 li 2 shi yong le zhe zhong ji shu lai shi xian zhi neng zhi zhen 。
  li 2:
  
  yi xia shi yin yong pian duan :
  class CJobDef : public CReferable
  {
  friend CArchive &operator << (CArchive &ar, const CJobDefPtr &cand)
  {
  ar << cand->getTag();
  CArchive ar_def(cand->getTag(), CArchive::WRITE);
  // write object attributes to ar_def
  return ar;
  }
  friend CArchive &operator >> (CArchive &ar, CJobDefPtr &cand)
  {
  int tag;
  ar >> tag;
  CArchive ar_def(tag, CArchive::READ);
  // read object attributes from ar_def
  cand.impersonate(tag);
  return ar;
  }
  };
  class CJobInst : public CReferable
  {
  friend CArchive & operator << ( CArchive &ar, const CJobInstPtr &cand)
  {
  ar << cand->m_defPtr;
  return ar;
  }
  friend CArchive & operator >> (CArchive &ar, CJobInstPtr &cand)
  {
  CJobDefPtr defPtr = new CJobDef;
  ar >> defPtr;
  cand->m_defPtr = defPtr;
  return ar;
  }
  };
C++引用计数的智能指针有效回收方法

  tu 4: zuo ye dui xiang yu CReferableCache quan ju dui xiang de jiao hu
  tu 4 miao shu le xi tong zhong lei CScheduler、CJobDefPtr、CJobDef、CReferableCache zhi jian de jiao hu , lei CReferableCache ju you jing tai cheng yuan fang fa getUniqueTag()、addObject()、deleteObject()。 dang yi ge dui CJobDef de zhi neng zhi zhen chuang jian shi , ru xia :
  
  yi xia shi yin yong pian duan :
  CJobDefPtr jobDefPtr = new CJobDef
  CScheduler hui gou zao CJobDefPtr he yi ge CJobDef dui xiang , dang dui xiang gou zao shi , hui tong guo CJobDef ji lei de CReferable gou zao han shu tiao yong getUniqueTag() fang fa , zhe jiu wei mei ge CJobDef dui xiang chuang jian le yi ge wei yi de shi bie biao ji (tag)。 jie xia lai ,CJobDef dui xiang bei fu gei CJobDefPtr dui xiang , hou zhe hui tiao yong ta zi ji de set() fang fa ba CJobDef dui xiang tian jia jin lai 。
  dang tiao yong CJobDefPtr fu zhi cao zuo fu han shu shi , ye hui tiao yong addObject() fang fa , jia ru shi di yi ci fu zhi de hua , ta hui ba CJobDef dui xiang tian jia jin quan ju CReferableCache; dang zhi neng zhi zhen bei qing qiu ti huan you tag shi bie de ta nei bu de dui xiang yin yong shi ,impersonate() fang fa hui tiao yong getObject() fang fa , jia ru impersonate() fang fa wei zhao dao CReferableCache zhong biao ji de dui xiang , na me ,CJobDefPtr dui xiang hui ti huan ta de nei bu dui xiang biao ji , bing ba ta zi shen tian jia dao CReferableCache huan cun ji zhong ; zui hou , dang CJobDefPtr bei shan chu ji dui xiang de yin yong ji shu wei ling shi ,deleteObject() fang fa ci shi hui bei tiao yong 。
  zai ci suo miao shu de shi jian tiao du xi tong , yi ban shi yong zai shi chang zi xun shu ju gong si zhong , qi hui zai wang luo ji qun gong zuo zhan shang chu fa ji suan ren wu , dang cong shi jie ge chu de ling shou shang hui ji suo xu xin xi zhi hou , zai mei zhou de san tian zhi zhong , dou hui chu fa ji suan ren wu , er zhe san tian zhong de ren yi shi ke , xi tong ke neng ye yao zai ji qun gong zuo zhan shang yun xing chao guo 20 wan ge ren wu 。 yin ci , ruan jian zai he li nei cun ji CPU xiao hao de qian ti xia , zhi chi chong xin qi dong , jiu xian de fei chang chong yao le 。 biao 1 xian shi le zai xi tong zhong yun xing zhe duo ge ji suan ren wu shi , shi jian tiao du shou hu jin cheng zai mei ci chong qi hou de nei cun xiao hao , zai xi tong chong qi hou , jiao xiao de nei cun xiao hao yao gui gong yu ruan jian zhong shi yong le shang wen fang fa lai chuan xing ji fan chuan xing hua bu chang yong de lei dui xiang de na xie mo kuai 。 dang ren wu wan cheng shi , nei cun zui zhong jiang bei hui shou 。
  biao 1: zai ruan jian mei ci chong qi hou de tiao du xi tong suo yong nei cun da xiao
  yun xing ren wu shu
  ruan jian chong qi qian de nei cun zhan yong da xiao
  ruan jian chong qi hou de nei cun zhan yong da xiao
  5000
  25M
  32M
  100000
  370M
  413M
  200000
  730M
  795M【原文】【汉音对照
 
 
 
 
 
 
 
 
 
日版宠物情人插曲《Winding Road》歌词

日版宠物情人2017的插曲,很带节奏感,日语的,女生唱的。 最后听见是在第8集的时候女主手割伤了,然后男主用嘴帮她吸了一下,插曲就出来了。 歌手:Def...

兄弟共妻,我成了他们夜里的美食

老钟家的两个儿子很特别,就是跟其他的人不太一样,魔一般的执着。兄弟俩都到了要结婚的年龄了,不管自家老爹怎么磨破嘴皮子,兄弟俩说不娶就不娶,老父母为兄弟两操碎了心...

如何磨出破洞牛仔裤?牛仔裤怎么剪破洞?

把牛仔裤磨出有线的破洞 1、具体工具就是磨脚石,下面垫一个硬物,然后用磨脚石一直磨一直磨,到把那块磨薄了,用手撕开就好了。出来的洞啊很自然的。需要猫须的话调几...

我就是扫描下图得到了敬业福和爱国福

先来看下敬业福和爱国福 今年春节,支付宝再次推出了“五福红包”活动,表示要“把欠大家的敬业福都还给大家”。 今天该活动正式启动,和去年一样,需要收集“五福”...

冰箱异味产生的原因和臭味去除的方法

有时候我们打开冰箱就会闻到一股异味,冰箱里的这种异味是因为一些物质发出的气味的混合体,闻起来让人恶心。 产生这些异味的主要原因有以下几点。 1、很多人有这种习...

 
 
   yin yong ji shu zhi zhen shi fou neng you xiao di hui shou , dui xi tong yi wai guan ji zhi hou shu ju de hui fu lai shuo zhi guan chong yao , yao hai shi yao bi mian dui xiang fu zhi 。    zen yang cong zai nan xing gu zhang zhong , hui fu yi ge chang qi yun xing 、 xi tong ji de hou tai shou hu jin cheng huo zhe fu wu , zai ru jin de ruan jian she ji guo cheng zhong , yi cheng wei le yi ge chong yao de kao lv yin su 。 dang zhe xie ruan jian shi you C++ yu yan bian cheng , bing shi yong le yin yong ji shu de zhi neng zhi zhen shi , na me , zhi neng zhi zhen de you xiao hui shou , dui xi tong shi fou ju you ke shen suo ji de hui fu neng li 、 shen zhi zheng que di ji xu wei wan cheng de cao zuo lai shuo , dou xian de zhi guan chong yao 。    zai ben wen zhong , miao shu le yi zhong fang fa , ke cong guan ji zhi hou de ruan jian hui fu zhong , you xiao di hui shou yin yong ji shu zhi zhen , er qie ci fang fa zai nei cun zhan yong fang mian ye fei chang gao xiao , zhe zhong fang fa de yao hai zai yu bi mian dui xiang fu zhi , er dui xiang fu zhi tong chang shi you C++ zhong zhi zhen yin yong de chuan xing hua yu fan chuan xing hua zhe zhong chuan tong ji shu chan sheng de 。 dang cong cun dang wen jian zhong fan chuan xing hua shi , ben fang fa shi yong le biao ji (tag) lai wei yi di shi bie zhi zhen dui xiang , qie zai xi tong hui fu shi you yi ge dui xiang huan cun lai bao cun zhi zhen yin yong 。    ben wen yi yi ge ji yu shi jian de shang ye shi shi zuo ye tiao du xi tong lai jin xing yan shi , qi tong chang you da xing shi chang zi xun gong si shi yong , tian tian dou hui zai ji qun gong zuo zhan shang chu li shu bu sheng shu de ji suan ren wu 。    wei shen me xu duo C++ ruan jian xiang mu hui shi yong zi dong nei cun zhi li ji shu ne , yin wei ta you yi xia hao chu :   ² dai ma an quan xing 。 bi mian le tai zao shi fang yi ge dui xiang suo dai lai de feng xian 。   ² dai ma zheng que xing 。 bi mian le wang ji shi fang wei shi yong nei cun suo dai lai de feng xian 。   ² dai ma mo kuai xing 。 dai ma zhong bu zai xu yao dian zhui zhe yu cheng xu wu guan de bao ji dai ma 。   ² bian cheng jian dan xing 。 xian zai ke jia ding yi zhong wu xian nei cun de ji suan mo shi 。   ² bian cheng gao xiao xing 。 cheng xu yuan bu zai dan xin nei cun zhi li wen ti 。    yin yong ji shu zhi neng zhi zhen , you shi ye cheng wei “ ji shu ti shu yu ”, shi yi zhong sheng ming qi shou guan de dui xiang , qi dui yin yong ta de shu liang , you yi ge nei bu de ji shu qi 。 dang nei bu yin yong ji shu wei ling shi , zhe xie dui xiang hui zi dong xiao hui zi shen , zhe shi yi zhong fei chang you yong de ji shu , yi yun yong zai xu duo C++ ruan jian chan pin xiang mu zhong , yin wei jian dan yi xing , qie wu xu dui yu yan huo bian yi qi jin xing ren he kuo zhan 。    yin yong ji shu zhi neng zhi zhen neng jin yi bu ding yi wei yi ti shi huo fen li shi , yi ti shi zhi neng zhi zhen ba yin yong ji shu fang zai zi shen nei , er fen li shi zhi neng zhi zhen ze ba yin yong ji shu fang zai dui xiang zhi wai 。 zai ben wen zhong , shi yong de shi fen li shi zhi neng zhi zhen fang an , zhe xu yao zai fang wen shi ji dui xiang zhi zhen zhi qian , zai zhi neng zhi zhen mo ban dui xiang zhong chong zai -> huo * cao zuo fu , cong ben zhi shang lai shuo , zhe ye shi dai li (PRoxy) she ji mo shi de yi ge te li 。    jiu mu qian lai shuo , huan mei you yi zhong fang an yi gao xiao li yong nei cun de fang shi miao shu le zen yang hui fu zhi neng zhi zhen , er chuan tong de C++ dui xiang chuan xing yu fan chuan xing hua fang fa , hui dao zhi nei cun di xiao , yin wei dang yi ge fan chuan xing hua de dui xiang peng dao yi ge dui ta de yin yong shi , zong shi hui chuang jian yi ge xin dui xiang , zai zui huai de qing kuang xia , zhe hui ba yi ge hui fu hou de shou hu jin cheng de nei cun xiao hao liang , tui dao yi ge wu fa jie shou de gao du , zhi shi ta wu fa ji xu yun xing xia qu 。    wen ti de yin chu    chuan tong dui xiang de chuan xing yu fan chuan xing hua fang an , ye neng shi xian zhi neng zhi zhen , zhi bu guo zai nei cun shang bi jiao di xiao er yi 。 zai zhe xie chuan tong fang an zhong , dang yi ge dui xiang chuan xing hua shi , dui xiang nei de cheng yuan zhi zhen bei jie yin yong , ta de nei rong yu dui xiang yi qi “ chuan xing ” jin cun dang wen jian zhong 。 zhe zhong fang fa de wen ti zai yu , dang fan chuan xing hua shi , cheng yuan zhi zhen hui zai ci gou zao , qie shi mei ge hui fu de dui xiang dou hui zhe yang 。    xia mian yi ji yu shi jian de zuo ye tiao du xi tong lai jin xing jiang jie , zuo ye ding yi zai CJobDef dui xiang zhong , qi bao han le zuo ye de jing tai shu xing , ru ta zhi xing de ming ling 、 gong zuo mu lu 、 ji zuo ye zhi xing shi de yong hu ID。 er zuo ye ding yi de yun xing shi li ze bao zhuang zai CJobInst dui xiang zhong , qi bao han le yi xie yu shi li you guan de shu xing , ru ta de jin cheng ID、 zhi xing shen shu 、 ji yun xing li shi ji lu 。 zai lei ceng ci shang , mei ge CJobInst dui xiang dou bao han le yi ge cheng yuan , qi yin yong dao chu fa zhe ci zuo ye shi li de yuan shi CJobDef dui xiang 。    tu 1 shi ruan jian ting zhi yun xing zhi qian de xi tong , yun xing shi CJobInst dui xiang de duo ge shi li ke neng hui yin yong zhi tong yi ge CJobDef dui xiang 。 zai ruan jian ting zhi ji hui fu hou , chuan tong chuan xing hua dui xiang hui fu fang fa , hui dao zhi wei mei ge yun xing de CJobInst dui xiang , dou chuang jian yi ge CJobDef dui xiang , ru tu 2 zhong suo shi 。 [url=http://www.wangchao.net.cn/bbs/pydetail_1785441.html][img]http://image.wangchao.net.cn/it/1323423280322.jpg[/img][/url]    tu 1: hui fu zhi qian de dui xiang tu [url=http://www.wangchao.net.cn/bbs/pydetail_1785441.html][img]http://image.wangchao.net.cn/it/1323423295540.jpg[/img][/url]    tu 2: nei cun di xiao hui fu zhi hou de dui xiang tu    zhe zhong qing kuang fa sheng zai chuan tong de C++ lei dui xiang zhong zhi zhen cheng yuan chuan xing hua yu fan chuan xing hua shi , li 1, shi yi duan dai you chong zai >> yu << cao zuo fu , chuan xing ji fan chuan xing hua CJobInst yu CJobDef lei zhi zhen de CArchive lei dai ma , ye zheng shi le zhe dian 。    li 1: yi xia shi yin yong pian duan : class CJobDef   {   friend CArchive & Operator >> (CArchive &ar, CJobDef *def)   {   ar >> def->command;   }   friend CArchive & operator << (CArchive &ar, CjobDef *def)   {   ar << def->command;   }   private:   std::string command;   };   class CJobInst   {   friend CArchive & operator >> (CArchive &ar, CJobInst *inst)   {   inst->m_def = new CJobDef;   ar >> inst->m_def;   }   friend CArchive & operator << (CArchive &ar, const CJobInst *inst)   {   ar << inst->m_def;   }   private:   CJobDef *m_def;   };    zai CJobInst zhong chuan xing hua CJobDef de si you cheng yuan m_def she ji dao tiao yong CArchive lei zhong shi dang de << cao zuo fu , chong zai de << cao zuo fu tong guo ba dui xiang shu xing chuan xing hua jin yi ge yong jiu de cun dang wen jian , lai shi xian dui CJobDef zhi zhen de chuan xing hua ; fan chuan xing hua CJobDef zhi zhen she ji dao gou zao yi ge xin de dui xiang , bing tiao yong >> cao zuo fu cong cun dang wen jian zhong geng xin shu xing 。    jie jue fang an    yin yong ji shu zhi neng zhi zhen shi you ji xu zi CReferable lei yi ge dui xiang shi xian de , qi bao han le yi ge si you yin yong ji shu qi ji yong yu xiu gai qi zhi de increaseReferenceCount() yu decreaseReferenceCount() fang fa , er xiang ying de Ref mo ban lei , tong guo ->、*、= cao zuo fu chong zai , ye shi xian le fang wen ci dui xiang ji dui sheng ming qi de zhi li 。Ref mo ban dui zhi neng zhi zhen de fu zhi cao zuo , hui di zeng dui xiang de yin yong ji shu , er ta de xi gou han shu hui di jian ji shu 。 zhi neng zhi zhen zhong de dui xiang zhi dang ta de yin yong ji shu wei ling shi bei xiao hui 。 zai shang mian de zuo ye tiao du xi tong zhong ,CJobDef dui xiang bei bao zhuang zai yi ge CJobDefPtr lei xing zhong , qi you yi xia yu ju ding yi : yi xia shi yin yong pian duan : typedef Ref<CJobDef> CJobDefPtr;    zhe ge CJobDefPtr lei xing , zheng shi lei CScheduler suo yong dao de lei xing 。 dang yong hu ti jiao yi ge zuo ye dao shi jian zuo ye tiao du qi shi , hui chan sheng yi ge CJobDefPtr lei xing xin de dui xiang , qie hui fu yu ta CJobDef dui xiang ; ci hou , dang zuo ye shi li chuang jian shi , ye zheng shi zhe ge CJobDefPtr lei xing fu yu gei le shi li 。 tu 3 yan shi le lei CScheduler shi yong de CJobDefPtr lei xing 。 [url=http://www.wangchao.net.cn/bbs/pydetail_1785441.html][img]http://image.wangchao.net.cn/it/1323423295667.jpg[/img][/url]    tu 3: zuo ye ding yi lei guan xi tu    zai CJobDefPtr lei zhong , fu zhi = cao zuo fu di zeng le CJobDef dui xiang CReferable ji lei zhong de yin yong ji shu , er delete cao zuo fu di jian le zhe ge yin yong ji shu 。 bao zhuang zai CJobDefPtr dui xiang zhong de CJobDef dui xiang bu hui bei xiao hui , zhi dao ta de yin yong ji shu wei ling , zhe ye shuo ming le zai xi tong zhong , mei you qi ta ren he dui xiang yin yong CJobDef dui xiang , ta ke yi an quan di bei xiao hui le 。    zai ci ti xing , cong zuo ye zhong chuang jian de zuo ye shi li , bei bao zhuang zai yi ge CJobInst lei zhong 。 yu CJobDef yi yang , lei CScheduler zhi zhi dao ta dui ying ban ben de zhi neng zhi zhen CJobInstPtr, er ci dui xiang de shi li ye hui yi zhi bao chi dao mei you dui ta de yin yong wei zhi 。    ling wai , zai xi tong zhong , huan bao kuo le ling wai san ge te xing , yi bian shi tiao du xi tong ke gao xiao di hui fu :   ² lei CReferable zeng jia le yi ge tag shu xing , yi wei yi di shi bie mei ge chuang jian de zhi zhen shi li , tong shi you yi ge getTag() fang fa ke yong yu fang wen ci shu xing 。   ² Ref mo ban lei zai cheng wei CReferableCache de quan ju dui xiang huan cun zhong zhi li ta de dui xiang , ci quan ju dui xiang huan cun ke you qi ta zhi neng zhi zhen dui xiang fang wen 。   ² Ref mo ban lei tian jia le yi ge impersonate() fang fa , qi da ying yi ge zhi neng zhi zhen yi gei ding de tag zhuan huan wei ling yi ge zhi neng zhi zhen 。    dang yi ge xin de CJobDefPtr huo CJobInstPtr bei chuang jian shi , zai CReferable ji lei gou zao han shu zhong , hui fen pei gei dui xiang wei yi de yi ge tag。 zhe ge tag ke you ji zhong fang shi chan sheng , dan ren yi zhong fang shi dou bi xu bao zheng zai mei ci ruan jian yun xing shi , dou hui you yi ge wei yi de ID。 yi ge jian dan de fang an shi shi yong yi ge jing tai 、 quan ju de ji shu qi dui xiang , qi zai cun dang wen jian zhong cun chu le shang yi ci chan sheng de ID, you ci ke bao zheng shen zhi zai you duo ge ruan jian shi li yun xing de tiao jian xia , dou neng dan tiao bu chong fu di di zeng ci ID。    fen pei gei zhi neng zhi zhen de tag, wei yi di biao shi chu yi ge zhi zhen , er ba ci tag cun ru yi ge cun dang wen jian jiu shi dui xiang chuan xing hua guo cheng de ze ren le 。 dui xiang de chuan xing hua guo cheng , ke tong guo CReferable ji lei de getTag() fang fa , lai fang wen ci tag, jie xia lai , dui xiang de fan chuan xing hua guo cheng shi yong ci tag, zai ruan jian hui fu shi , lai chong jian zheng que de dui xiang zhi zhen shi li yin yong 。 xia mian shi fan chuan xing hua guo cheng bi xu zhi xing de bu zhou :   ² cong cun dang wen jian zhong hui fu tag。   ² cong tag biao shi de cun dang wen jian zhong , hui fu dui xiang shu xing 。   ² yi ci tag wei jie tiao yong impersonate() fang fa , hui fu zheng que de zhi zhen dui xiang de yin yong 。   Impersonate() hui dui shi fou yi ge tag suo yin le zai quan ju CReferableCache dui xiang ji zhong de yi ge dui xiang jin xing jian cha , jia ru wei zhao dao ci tag xiang ying de dui xiang , na me ci dui xiang hui tian jia dao CReferableCache zhong , bing yong ci tag zuo wei ta de suo yin zhi 。 ran er , jia ru yi ge dui xiang yi jing cun zai yu quan ju CReferableCache dui xiang ji zhong , tong guo yi xin yin yong lai tiao yong set() fang fa , ni ke yi she qi lao yin yong , qie wu guan de dui xiang fu zhi cao zuo ye hui zi dong bei shan chu 。 li 2 shi yong le zhe zhong ji shu lai shi xian zhi neng zhi zhen 。    li 2: yi xia shi yin yong pian duan : class CJobDef : public CReferable   {   friend CArchive &operator << (CArchive &ar, const CJobDefPtr &cand)   {   ar << cand->getTag();   CArchive ar_def(cand->getTag(), CArchive::WRITE);   // write object attributes to ar_def   return ar;   }   friend CArchive &operator >> (CArchive &ar, CJobDefPtr &cand)   {   int tag;   ar >> tag;   CArchive ar_def(tag, CArchive::READ);   // read object attributes from ar_def   cand.impersonate(tag);   return ar;   }   };   class CJobInst : public CReferable   {   friend CArchive & operator << ( CArchive &ar, const CJobInstPtr &cand)   {   ar << cand->m_defPtr;   return ar;   }   friend CArchive & operator >> (CArchive &ar, CJobInstPtr &cand)   {   CJobDefPtr defPtr = new CJobDef;   ar >> defPtr;   cand->m_defPtr = defPtr;   return ar;   }   }; [url=http://www.wangchao.net.cn/bbs/pydetail_1785441.html][img]http://image.wangchao.net.cn/it/1323423295799.jpg[/img][/url]    tu 4: zuo ye dui xiang yu CReferableCache quan ju dui xiang de jiao hu    tu 4 miao shu le xi tong zhong lei CScheduler、CJobDefPtr、CJobDef、CReferableCache zhi jian de jiao hu , lei CReferableCache ju you jing tai cheng yuan fang fa getUniqueTag()、addObject()、deleteObject()。 dang yi ge dui CJobDef de zhi neng zhi zhen chuang jian shi , ru xia : yi xia shi yin yong pian duan : CJobDefPtr jobDefPtr = new CJobDef   CScheduler hui gou zao CJobDefPtr he yi ge CJobDef dui xiang , dang dui xiang gou zao shi , hui tong guo CJobDef ji lei de CReferable gou zao han shu tiao yong getUniqueTag() fang fa , zhe jiu wei mei ge CJobDef dui xiang chuang jian le yi ge wei yi de shi bie biao ji (tag)。 jie xia lai ,CJobDef dui xiang bei fu gei CJobDefPtr dui xiang , hou zhe hui tiao yong ta zi ji de set() fang fa ba CJobDef dui xiang tian jia jin lai 。    dang tiao yong CJobDefPtr fu zhi cao zuo fu han shu shi , ye hui tiao yong addObject() fang fa , jia ru shi di yi ci fu zhi de hua , ta hui ba CJobDef dui xiang tian jia jin quan ju CReferableCache; dang zhi neng zhi zhen bei qing qiu ti huan you tag shi bie de ta nei bu de dui xiang yin yong shi ,impersonate() fang fa hui tiao yong getObject() fang fa , jia ru impersonate() fang fa wei zhao dao CReferableCache zhong biao ji de dui xiang , na me ,CJobDefPtr dui xiang hui ti huan ta de nei bu dui xiang biao ji , bing ba ta zi shen tian jia dao CReferableCache huan cun ji zhong ; zui hou , dang CJobDefPtr bei shan chu ji dui xiang de yin yong ji shu wei ling shi ,deleteObject() fang fa ci shi hui bei tiao yong 。    zai ci suo miao shu de shi jian tiao du xi tong , yi ban shi yong zai shi chang zi xun shu ju gong si zhong , qi hui zai wang luo ji qun gong zuo zhan shang chu fa ji suan ren wu , dang cong shi jie ge chu de ling shou shang hui ji suo xu xin xi zhi hou , zai mei zhou de san tian zhi zhong , dou hui chu fa ji suan ren wu , er zhe san tian zhong de ren yi shi ke , xi tong ke neng ye yao zai ji qun gong zuo zhan shang yun xing chao guo 20 wan ge ren wu 。 yin ci , ruan jian zai he li nei cun ji CPU xiao hao de qian ti xia , zhi chi chong xin qi dong , jiu xian de fei chang chong yao le 。 biao 1 xian shi le zai xi tong zhong yun xing zhe duo ge ji suan ren wu shi , shi jian tiao du shou hu jin cheng zai mei ci chong qi hou de nei cun xiao hao , zai xi tong chong qi hou , jiao xiao de nei cun xiao hao yao gui gong yu ruan jian zhong shi yong le shang wen fang fa lai chuan xing ji fan chuan xing hua bu chang yong de lei dui xiang de na xie mo kuai 。 dang ren wu wan cheng shi , nei cun zui zhong jiang bei hui shou 。    biao 1: zai ruan jian mei ci chong qi hou de tiao du xi tong suo yong nei cun da xiao yun xing ren wu shu ruan jian chong qi qian de nei cun zhan yong da xiao ruan jian chong qi hou de nei cun zhan yong da xiao 5000 25M 32M 100000 370M 413M 200000 730M 795M
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
桌球宝贝_性感在蔓延(3)
桌球宝贝_性感在蔓延(2)
银杏树下清纯女孩(9)
银杏树下清纯女孩(8)
痞子的甘南日记
疑是银河落九天
雪域坝上四——纯美色
冬日恋歌——西城杨柳弄轻柔
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
 
©2005- 王朝网络 版权所有