object c ÄÚ´æ¹ÜÀí
¿´ÁËϹٷ½ÎĵµµÄ¹ØÓÚobject c µÄÄÚ´æ¹ÜÀí,×ܽáÏÂ:
ÔÚiphoneÖÐobject c ÖеÄÄÚ´æ¹ÜÀíÊÇͨ¹ý¼ÆÊýÆ÷À´¹ÜÀíµÄ,ÿ¸ö¶ÔÏóÄÚ²¿¶¼ÓÐÒ»¸ö¼ÆÊýÆ÷.н¨Ò»¸ö¶ÔÏó,»òÕßÕâ¸ö¶ÔÏ󱻯äËû¶ÔÏóÒýÓÃ,¶à»áʹ¼ÆÊýÆ÷¼Ó1.Retain Ôö¼Ó¼ÆÊýÆ÷Öµ release ¼õÉÙ¼ÆÊýÆ÷Öµ.µ±¼ÆÊýÆ÷Ϊ0ʱ¶ÔÏó¾Ídealloc×Ô¼º.
ÔÚobject cÖÐÄãÉú³ÉµÄÒ»¸ö¶ÔÏóÄÇôÄã¾ÍÓÐÔðÈÎÈ¥ÊÍ·ÅËü£¬ÄÚ´æ¹ÜÀíµÄÒ»°ã¹æÔò£º
You own any object you create by allocating memory for it or copying it.
Related methods: alloc, allocWithZone:, copy, copyWithZone:, mutableCopy, mutableCopyWithZone:
If you are not the creator of an object, but want to ensure it stays in memory for you to use, you can express an ownership interest in it.
Related method: retain
If you own an object, either by creating it or expressing an ownership interest, you are responsible for releasing it when you no longer need it.
Related methods: release, autorelease
Conversely, if you are not the creator of an object and have not expressed an ownership interest, you must not release it.
¿¼ÂÇÏÂÃæÕâ¸öÀý×Ó£º
Thingamajig *thingamajig = [[Thingamajig alloc] init];
NSArray *sprockets = [thingamajig sprockets];
[thingamajig release];
thingamajig ÐèÒªrelease£¬ÒòΪºÜÏÔÈ»ÕâÀïÎÒÃÇÊÇthingamajig µÄowner¡££¨µÚÒ»Ìõ¹æÔò£©
ÄÇôsprockets Ϊʲô²»ÐèÒªreleaseÄØ¡£
Ê×ÏÈÎÒÃDz»ÊÇ sprockets µÄ creater.£¨µÚÒ»Ìõ¹æÔò£©,ÎÒÃÇҲûÓÐexpressing an ownership interest£¬ÒòΪÎÒÃÇûÓÐ
retainËü£¬£¨µÚ¶þÌõ¹æÔò£© ËùÒÔÎÒÃDz»¸ºÔðreleaseËü¡£
¾ßÌåÀ´¿´ thingamajig µÄ sprockets·½·¨µÄʵÏÖ£º
(NSArray *)sprockets {
NSArray *array;
array = [[NSArray alloc] initWithObjects:mainSprocket,auxiliarySprocket, nil];
return [array autorelease];
}
¿É¼û·ÖÅäµÄÄÚ´æÔÚ·
Ïà¹ØÎĵµ£º
ÒÔÇ°Ôø¾×ܽá¹ýһƪ(http://www.cppblog.com/franksunny/archive/2007/11/29/37510.html
)£¬¹ØÓÚÔÚ
C
ÖÐÈçºÎµ÷ÓÃ
C++
µÄ´úÂ룬µ±Ê±²¢Î´×öÍêÈ«µÄÕ¹¿ª£¬Ö»ÊǼòµ¥µÄ×öÁËϵ÷ÊÔ£¬×î½ü¿´µ½Ò»¸öÌâĿҪÇóʵÏÖ
C
ºÍ
C++
ÖдúÂëµÄ»¥Ïàµ÷Óã¬Æä½á¹ûËäÈ»¶¼ÊÇͨ¹ý
extern “C”
À´ÊµÏÖ
£¬µ«ÊǾßÌ廹ÊÇÓÐЩ²î±ðµÄ¡ ......
ÎÊÌâÃèÊö£ºÒ»Ë³ÐòÎļþÖÐÖÁ¶à´æÔÚ10000000¸ö¼Ç¼£¬Ã¿Ìõ¼Ç¼¶¼ÊÇÒ»¸ö7λÕûÊý£¬Çë¶Ô´ËÎļþÖÐÊý¾Ý½øÐÐÅÅÐò¡£
ÒªÇó£º1.³ÌÐò¿ÉʹÓÃÄÚ´æÖ»ÓÐ1MB¡£2.³ÌÐòÔËÐÐʱ¼ä¾¡¿ÉÄܵĶ̡£
²¹³ä˵Ã÷£ºÃ¿¸ö¼Ç¼¶¼ÊÇÒ»¸ö7λÕýÕûÊý£¬²¢ÇÒûÓÐÆäËûµÄ¹ØÁªÊý¾Ý£¬Ã¿¸öÕûÊýÖÁ¶àÖ»ÄܳöÏÖÒ»´Î¡£
ʵÏÖ¸ÙÒª£º
ÔÚÏÖʵÖУ¬Î»Í¼ºÍλÏòÁ¿ºÜ³£¼û£¬ÎÒÃÇ¿ÉÒÔÊ¹Ó ......
ΪʲôÐèҪʹÓÃextern "C"ÄØ£¿C++Ö®¸¸ÔÚÉè¼ÆC++֮ʱ£¬¿¼Âǵ½µ±Ê±ÒѾ´æÔÚÁË´óÁ¿µÄC´úÂ룬ΪÁËÖ§³ÖÔÀ´µÄC´úÂëºÍÒѾдºÃC¿â£¬ÐèÒªÔÚC++Öо¡¿ÉÄܵÄÖ§³ÖC£¬¶øextern "C"¾ÍÊÇÆäÖеÄÒ»¸ö²ßÂÔ¡£
¡¡¡¡ÊÔÏëÕâÑùµÄÇé¿ö:Ò»¸ö¿âÎļþÒѾÓÃCдºÃÁ˶øÇÒÔËÐеúÜÁ¼ºÃ£¬Õâ¸öʱºòÎÒÃÇÐèҪʹÓÃÕâ¸ö¿âÎļþ£ ......
ת×Ô£ºhttp://blog.csdn.net/Lambol_8309/archive/2009/09/06/4524453.aspx
Ôø¾Åöµ½¹ýÈÃÄãÃԻ󲻽⡢ÀàËÆÓÚint * (* (*fp1) (int) ) [10];ÕâÑùµÄ±äÁ¿ÉùÃ÷Â𣿱¾ÎĽ«ÓÉÒ×µ½ÄÑ£¬Ò»²½Ò»²½½Ì»áÄãÈçºÎÀí½âÕâÖÖ¸´ÔÓµÄC/C++ÉùÃ÷¡£
¡¡¡¡ÎÒÃǽ«´ÓÿÌì¶¼ÄÜÅöµ½µÄ½Ï¼òµ¥µÄÉùÃ÷ÈëÊÖ£¬È»ºóÖð²½¼ÓÈëconstÐÞÊηûºÍtypedef£¬»¹Óк¯ÊýÖ¸Õ ......