è¿œå ã®èšèªããŒã«ãå°å ¥ããããšã«ãããCã§ã®ãµãŒããŒããã°ã©ã ã®äœæãç°¡çŽ åããæ¹æ³ã«ã€ããŠã®è°è«ã®ã¢ã€ãã¢ãæäŸããããšæããŸãã ãã®ãããã¯ã¯ããã«ãã¹ã¬ãããŸãã¯éåæã³ãŒãã®äœæã«å¯ŸåŠããªããã°ãªããªãã£ããã¹ãŠã®éçºè ã«ãšã£ãŠèå³æ·±ããã®ã«ãªããšæããŸãã
çŸæç¹ã§ã¯ãããŒã«ãããïŒããŒãµãŒãžã§ãã¬ãŒã¿ãŒãCããŒãµãŒãããã³éšåçã«C ++ïŒã®äœæãã»ãŒå®äºããŠããŸããããã«ãããèšèªæ¡åŒµæ©èœããµããŒããããã©ã³ã¹ã¬ãŒã¿ãŒã®äœæãéå§ã§ããŸãã ããããç¶è¡ããåã«ãã¯ãŒã¯ã·ã§ããã§ååãšçžè«ããå¿ãåãããã人ãèŠã€ããããšæããŸãã
ãã«ãã¹ã¬ããã®éåæãµãŒããŒã«ã€ããŠã§ãã éåæ-ã€ãŸããã€ãã³ãããŒã¹ã®é¡§å®¢ãµãŒãã¹ããžãã¯ïŒepoll / kqueueïŒã䜿çšããäžåºŠã«1ã€ã®ã¹ã¬ããã§è€æ°ã®ã¯ã©ã€ã¢ã³ãã«ãµãŒãã¹ãæäŸããŸãã ãã«ãã¹ã¬ãã-ææ°ã®ãã«ãã³ã¢ããã»ããµãããã«å©çšã§ããããšãæå³ããåãããã»ã¹å ã®è€æ°ã®ã¹ã¬ããã«ããæ¥ç¶ã®äžŠè¡ã¡ã³ããã³ã¹ãå®è¡ããŸãã
éåæãµãŒãã¹ã¢ãã«ã䜿çšãããšãéåžžã«é«ãè² è·ã§åäœããããã«æãæºåããããµãŒããŒãäœæã§ããŸãã ãã ããéåæïŒéããããã³ã°ïŒã³ãŒãã¯ãåæããããã³ã°ã³ãŒããããäœæãå°é£ã§ãã ããã«ãéåæãã«ãã¹ã¬ããã³ãŒããèšè¿°ããããšã¯ã¯ããã«å°é£ã§ããå ±æããŒã¿ãžã®ã¢ã¯ã»ã¹ãåæãããšãã«ãã¹ãç¯ããããããã®ãããªãšã©ãŒãæ€åºããããšã¯éåžžã«å°é£ã§ãã ããã¯ãå®éã«ã¯ãã«ãã¹ã¬ããã®ãµããŒããå®å šã«æåŠããããšãè³¢æã§ãããšããäºå®ã«ã€ãªãããŸãã
ãã®ãããªããã°ã©ã ã®äœæã§ããçšåºŠã®çµéšãç©ãã åŸãã¹ã¬ããåæã®äž»ãªåé¡ã®è§£æ±ºçãæšæºçãªæ¹æ³ã§è§£æ±ºãããŠããããšã«æ°ã¥ãå§ããŸããããã®äœ¿çšã¯èšèªã¬ãã«ã§èªååã§ããéçºè ã®ã¿ã¹ã¯ãå€§å¹ ã«ç°¡çŽ åã§ããŸãã 次ã«ãåæ§ã®ã¢ãããŒãã䜿çšããŠãéåæã€ãã³ãåŠçã³ãŒãã®èšè¿°ãç°¡çŽ åã§ããããšãèŠãŸããã ãœãªã¥ãŒã·ã§ã³ã®æãããªäžè¬æ§ã®ããã«ããããã®çŽæ¥é¢ä¿ã®ãªãã¿ã¹ã¯ã®ããã®èšèªè¿œå ã®åäžã»ãããææ¡ããŸãã
ã¢ã€ãã¢ã¯éåžžã«åçŽã§ãããããè€éããæããããªãããã«ãCãžã®è¿œå ã«é¢ããäž»ãªãã€ã³ãããªã¹ãããŸãããããã®è¿œå ããMtèšèªããšåŒã³ãŸãã
ã ããå±±ã¯ïŒ
- ãªããžã§ã¯ããžã®ã¢ã¯ã»ã¹ãåæããèªåãã¥ãŒããã¯ã¹å¶åŸ¡ã
- éåžžã®ã·ãŒã±ã³ã·ã£ã«é¢æ°ãšããŠèšè¿°ãããéåæåŠçãã§ãŒã³ã
- 泚é-ãœãŒã¹ããã¹ãã®éçåæã®ããã®ããã°ã©ã èŠçŽ ã®è¿œå 説æã
- çµã¿èŸŒã¿ã®ãªã³ã¯ã«ãŠã³ãã¡ã«ããºã ã
- C ++ããæã䟿å©ãªæ©èœãåããã
- CäºæãC ABIãžã®ç·å¯ãªãã€ã³ãã£ã³ã°ã æåã®å®è£ ã¯ãMtããCãžã®ãã©ã³ã¹ã¬ãŒã¿ãŒã§ãã
次ã«ãåè¿œå ã«ã€ããŠè©³ãã説æããŸãã C ++ã®ã³ãŒãã®äŸãããã€ã瀺ããŸããããã¯ãMtã®åçã®ã³ãŒããšã®é¢é£ä»ããç°¡åã ããã§ãã
1.èªåãã¥ãŒããã¯ã¹å¶åŸ¡
äžè¬çãªãªã¯ãšã¹ãåŠçã¹ããŒã ãæ€èšããŠãã ããã ãµãŒããŒã®å®è£ ã§ããMyFrontendã¯ã©ã¹ã®ãªããžã§ã¯ãããããšããŸãã ã¯ã©ã€ã¢ã³ããããªã¯ãšã¹ããåä¿¡ããŠââãã³ãŒãããåŸããµãŒããŒãªããžã§ã¯ãprocessRequestïŒïŒã®ã¡ãœãããåŒã³åºããŸãã ãã®ã¡ãœããã¯ããµãŒããŒã®å éšç¶æ ã®å€æŽãåŒãèµ·ããããã€ãã®æäœãå®è¡ããŸãã ããšãã°ããªã¯ãšã¹ããåŠçããçµæããªã¯ãšã¹ãã®æ°num_requestsã®ã«ãŠã³ã¿ãŒãå¢å ãããšããŸãã
class MyFrontend
{
private :
Mutex state_mutex ;
unsigned num_requests ;
public :
void processRequest ( )
{
state_mutex. lock ( ) ;
++ num_requests ;
state_mutex. unlock ( ) ;
}
} ;
Mtã¯ãæååæã®å¿ èŠæ§ãæé€ããŸãã
async object MyFrontend
{
private :
unsigned num_requests ;
public :
async void processRequest ( )
{
++ num_requests ;
}
} ;
éåæãªããžã§ã¯ãã¯ããªããžã§ã¯ãã®ã¹ã¬ããã»ãŒãã¯ã©ã¹ã宣èšããŸãã ãã®ãããªãªããžã§ã¯ãã¯éåæãšåŒã°ããŸãã æå®ãããMtã³ãŒãã®äŸã¯ãæå®ãããC ++ã®äŸã«çžåœããã³ãŒãã«å€æãããŸãã
ããã§ããªã¯ãšã¹ããåŠçããããã«ãMyFrontendãMyBackendãªããžã§ã¯ãã®doSomethingïŒïŒã¡ãœãããåŒã³åºããnum_backããã¯ãšã³ãã¢ã¯ã»ã¹ã«ãŠã³ã¿ãŒããã©ã¡ãŒã¿ãŒãšããŠæž¡ãå¿ èŠããããšããŸãã ããã«ããããããã¯ã®å¯èœæ§ã«ã€ããŠèããããªããããã¹ãŠãéååž°çãã¥ãŒããã¯ã¹ã§åäœããããšãæãã§ããŸãã ãããè¡ãã«ã¯ãMyBackendã«ã¢ã¯ã»ã¹ããåã«state_mutexã解æŸããå¿ èŠããããŸãã
class MyFrontend
{
private :
Mutex state_mutex ;
unsigned num_requests ;
unsigned num_back ;
MyBackend * backend ;
public :
void processRequest ( )
{
state_mutex. lock ( ) ;
++ num_back ;
unsigned tmp_num_back = tmp_num_back ;
state_mutex. unlock ( ) ;
backend - > doSomething ( tmp_num_back ) ;
state_mutex. lock ( ) ;
++ num_requests ;
state_mutex. unlock ( ) ;
}
} ;
Mtã§ãåãããšïŒ
async object MyFrontend
{
private :
unsigned num_requests ;
unsigned num_back ;
MyBackend * backend ;
public :
async void processRequest ( )
{
call backend - > doSomething ( ++ num_back ) ;
++ num_requests ;
}
} ;
Mtãã©ã³ã¹ã¬ãŒã¿ãŒã¯ãstate_mutexã䜿çšããŠæäœãåå¥ã«æ¿å ¥ãããã©ã¡ãŒã¿ãŒãæž¡ãããã®äžæå€æ°ãå ¥åããŸãã åŒã³åºãæŒç®åã¯ãå¥ã®ãªããžã§ã¯ãã®éåæã¡ãœãããåŒã³åºãããéãstate_mutexããã¯ã解æŸããããšã匷調ããããã«å°å ¥ãããŸããã ããã«ãããã«ãããåŒã§éåæã¡ãœãããåŒã³åºãããšãæ瀺çã«çŠæ¢ã§ããŸãã
äžèšã®äŸã«å ããŠãããã¯ã䜿çšããä»ã®å€ãã®ã±ãŒã¹ãèªååãããŠããŸãïŒã€ãã³ãã®åŸ æ©ïŒã€ãã³ãã¯éåžžãåŸ æ©ã®å®äºã®ããã®æ¡ä»¶ãä¿è·ãããã¥ãŒããã¯ã¹ãšçµã¿åãããŠäœ¿çšââãããŸãïŒãåããªããžã§ã¯ãã®å¥ã®ã¡ãœãããããªããžã§ã¯ãã®éåæã¡ãœãããåŒã³åºããŸãã
ãããã£ãŠããªããžã§ã¯ãã®ç¶æ ã®åçŽãªããã¯ã管çãããšãã«ãã¹ãç¯ããªã¹ã¯ãæå°éã«æããŸãã ç§ã®èŠ³å¯ã«ããã°ããªããžã§ã¯ããžã®ã¢ã¯ã»ã¹ã®åæã1ã€ã§ã¯ãªãè€æ°ã®ããã¯ã䜿çšããŠå®è¡ãããå Žåããããã倱æããèšèšããããŸãïŒãªããžã§ã¯ããè€æ°ã®ç¬ç«ãããªããžã§ã¯ãã«åå²ããããããã¯ã1ã€ã«ããŒãžããå¿ èŠããããŸãã ãããã£ãŠã1ã€ã®ãã¥ãŒããã¯ã¹ã§æãåçŽãªã±ãŒã¹ãèªååããããšã«ãããã»ãšãã©ã®åæã®åé¡ã解決ããŸãã æåããã³ä»ã®ããªããã£ãã䜿çšããŠåæããæ©èœ
ä¿åããŸããã
2.éåæåŠçãã§ãŒã³
ç§ã®æèŠã§ã¯ãããã¯æãèå³æ·±ãçããã¢ã€ãã¢ã§ãã å®éã®ãµãŒãã¹ã®åäœã瀺ãäŸã䜿çšããŠèª¬æããŸãã
ç§ãã¡ã®ãµãŒããŒãåçãã¹ãã£ã³ã°ã®ããã³ããšã³ãã§ãããšããŸãããã ãŠãŒã¶ãŒã®åçãå«ãHTMLããŒãžã顧客ã«è¿ãããšãå®çŸããããšèããŠããŸãã ãã®ããŒãžã«ã¯ãåçã®ææè ã®ãããã¡ã€ã«ãšåçèªäœã®æ å ±ã衚瀺ãããŸãã åçã¯ãåçã®ææè ã®å人ã®ã¿ã衚瀺ã§ããŸãã ãããã£ãŠãHTTPèŠæ±ã«å¿çããã«ã¯ãå€æ°ã®å éšãµãŒãã¹ãããŒãªã³ã°ããŠå¿ èŠãªæ å ±ãåéããå¿ èŠããããŸãã
ãªã¯ãšã¹ãåŠçã¢ã«ãŽãªãºã ïŒ
- Cookie CookieãèªèšŒãµãŒããŒã«éä¿¡ããŠããŠãŒã¶ãŒãèå¥ããŸãïŒcheck_authïŒã
- æ¿èªã確èªãããããœãŒã·ã£ã«ã°ã©ããæäŸãããµãŒããŒã«ãªã¯ãšã¹ããéä¿¡ããŠããŠãŒã¶ãŒãåéãã©ããã確èªããŸãïŒcheck_friendsïŒã
- åçææè ã«å人ããŒã¿ãªããžããªïŒget_userinfoïŒã«ãªã¯ãšã¹ããéä¿¡ããŸãã
- check_friendsããã³get_userinfoããåçãåãåã£ãåŸãHTMLããŒãžãçæããŠã¯ã©ã€ã¢ã³ãã«éä¿¡ããŸãã
Cã®å®è£ ãã¹ã±ããããŸãããããã®äŸãç解ããããšã¯ã§ããŸããã 圌ã®ä»äºã¯ããã®ãããªåçŽãªéåæåŠçãã§ãŒã³ã®æåå®è£ ãããã«åä»ã§ãããã瀺ãããšã§ãã
// .
typedef struct {
// "" , .
MReferenced parent_referenced ;
// .
MMutex state_mutex ;
uint64_t owner_id ;
uint32_t photo_id ;
// 'true', .
bool cancel ;
// get_userinfo?
bool got_userinfo ;
// ( ).
uint32_t owner_carma ;
// check_friends?
bool got_friends ;
} HttpPhotoData ;
static void http_photo_data_init ( HttpPhotoData * data )
{
m_referenced_init ( ( MReferenced * ) data ) ;
m_mutex_init ( & data - > state_mutex ) ;
data - > cancel = false ;
data - > got_userinfo = false ;
data - > got_friends = false ;
}
static void http_photo__get_userinfo_ret ( uin32_t owner_carma,
void * _data ) ;
static void http_photo__check_auth_ret ( uint64_t client_id,
void * _data ) ;
static void http_photo__end ( HttpPhotoData * data ) ;
// .
void http_photo ( char * cookie_str,
uint64_t owner_id,
uint32_t photo_id )
{
HttpPhotoData * data = m_malloc ( sizeof ( HttpPhotoData ) ) ;
http_photo_data_init ( data ) ;
data - > owner_id = owner_id ;
data - > photo_id = photo_id ;
{
m_referenced_ref ( ( MReferenced * ) data ) ;
MCallbackDesc cb ;
m_callback_desc_init_refdata ( & cb, http_photod__get_userinfo_ret, data ) ;
get_userinfo ( & cb, owner_id ) ;
}
{
m_referenced_ref ( ( MReferenced * ) data ) ;
MCallbackDesc cb ;
m_callback_desc_init_refdata ( & cb, http_photod__check_auth_ret, data ) ;
check_auth ( & cb, cookie_str ) ;
}
m_referenced_unref ( ( MReferenced * ) data ) ;
}
// get_userinfo.
static void http_photo__get_userinfo_ret ( uint32_t owner_carma,
void * _data )
{
HttpPhotoData * data = ( HttpPhotoData * ) _data ;
m_mutex_lock ( & data - > state_mutex ) ;
if ( data - > cancel ) {
m_mutex_unlock ( & data - > state_mutex ) ;
return ;
}
data - > owner_carma = owner_carma ;
data - > got_userinfo = true ;
if ( data - > got_friends ) {
// , .
http_photo_end ( data ) ;
}
m_mutex_unlock ( & data - > state_mutex ) ;
}
// check_auth.
static void http_photo__check_auth_ret ( uint64_t client_id,
void * _data )
{
HttpPhotoData * data = ( HttpPhotoData * ) _data ;
m_referenced_ref ( ( MReferenced * ) data ) ;
MCallbackDesc cb ;
m_callback_desc_init_refdata ( & cb, http_photo__check_friends_ret, data ) ;
check_friends ( & cb, client_id, data - > owner_id ) ;
}
// check_friends.
static void http_photo__check_friends_ret ( bool friends,
void * _data )
{
HttpPhotoData * data = ( HttpPhotoData * ) _data ;
m_mutex_lock ( & data - > state_mutex ) ;
if ( data - > cancel ) {
m_mutex_unlock ( & data - > state_mutex ) ;
return ;
}
data - > got_friends = true ;
if ( ! friends ) {
// . .
data - > cancel = true ;
m_mutex_unlock ( & data - > state_mutex ) ;
return ;
}
if ( data - > got_userinfo ) {
// , .
http_photo_end ( data ) ;
}
m_mutex_unlock ( data - > state_mutex ) ;
}
// .
static void http_photo_end ( HttpPhotoData * data )
{
photo_send_page ( data - > owner_id, data - > photo_id, data - > owner_carma ) ;
}
çµæã®ã³ãŒãã¯è€éã§ãèªã¿ã«ããã§ãã æžã蟌ã¿ã®ã»ãšãã©ã®æéã¯ãæäœã®å¿ èŠãªé åºã®å®æçãªã¡ã³ããã³ã¹ã«è²»ããããŸããã
Mtã§ã®åçã®å®è£ ïŒ
async chain void http_photo ( char * cookie_str,
uint64_t owner_id,
uint32_t photo_id )
{
async call GetUserinfoCall get_userinfo ( owner_id ) ;
async call check_auth ( cookie ) ;
gives uint64_t client_id ;
async call check_friends ( client_id, owner_id )
gives bool friends ;
if ( ! friends ) {
//
return ;
}
GetUserinfoCall gives uint32_t owner_carma ;
// HTTP- .
photo_send_page ( owner_id, photo_id, owner_carma ) ;
}
å¿ èŠãªå®è¡é åºãæŽçãããšããéåžžã®äœæ¥ããã»ãŒå®å šã«è§£æŸãããŠããããšã«æ³šæããŠãã ããã ããã«ãçæãããCã³ãŒãã¯ãã«ãã¹ã¬ããããã°ã©ã ã§äœ¿çšã§ããŸãã
äžèšã®äŸã§ã¯ã2ã€ã®æ°ããæŒç®åã䜿çšãããŠããŸãã
- éåæåŒã³åºãã¹ããŒãã¡ã³ãã¯ãéåæåŒã³åºããèšè¿°ããŸãã ãã®æŒç®åã§äœ¿çšã§ããé¢æ°ã«ã¯ãç¹å¥ãªçœ²åãå¿ èŠã§ããæåã®ãã©ã¡ãŒã¿ãŒã¯ã³ãŒã«ããã¯ã§ãåŒã³åºããçµäºãããšåŒã³åºãããŸãã ã³ãŒã«ããã¯ã®çµäºã¯ãæåããã³ãŒã«ãå éšãšã©ãŒããŸãã¯ã¿ã€ã ã¢ãŠãã§ãã£ããã©ããã«é¢ä¿ãªããå¿ ããã¹ãŠã®çµæã§ã³ãŒã«ããå¿ èŠããããŸãã
- givesã¹ããŒãã¡ã³ãã¯ãæå®ãããéåæåŒã³åºãã®å®äºãåŸ æ©ãããã€ã³ããèšå®ããŸãã åŒã³åºãã«ãã£ãŠè¿ãããå€ã®ãªã¹ããã¹ã³ãŒãã«å°å ¥ããŸãã éåæåŒã³åºããšgiveã¹ããŒãã¡ã³ãã®ééã空ããå¿ èŠãããå ŽåãéåæåŒã³åºãã§ã¯åŒã³åºãã«ååãä»ããããåŒã³åºãã®ååãgiveã«ç€ºãããŸãïŒäžèšã®äŸã®GetUserinfoCallãåç §ïŒã
Cã§éåæãã§ãŒã³ãå€æãããšãã«Mtãè¡ãäž»ãªäœæ¥ã¯æ¬¡ã®ãšããã§ãã
- ãã§ãŒã³ç¶æ æ§é ïŒHttpPhotoDataïŒã«æ ŒçŽãããå€æ°ã®ã»ãããå®çŸ©ããŸãã
- é¢æ°ãå°ããªãã®ã«åå²ããŸãã ãã¬ãŒã¯ãã€ã³ãã¯éåæåŒã³åºãã¹ããŒãã¡ã³ãã§ãã
- ããã¯ãéåæåŒã³åºãã«ãã£ãŠéåãããCã¹ããŒãã¡ã³ããå€æããããšã«ããå¿ èŠãªå®è¡é åºãæäŸããåºå®ã«ãŒã«ã«åŸã£ãŠã¹ããŒãã¡ã³ããåçã®éåææ§é ã«äžããŸãã
Mtã®åäžã®é¢æ°ã§ã¯è¡šçŸã§ããªãè€éãªæäœãã§ãŒã³ã®äžŠåå®è¡ã¯ãããã€ãã®ç°ãªãéåæãã§ãŒã³ã䜿çšããŠå®è£ ã§ããŸãã ã€ãŸãããã§ãŒã³å ã®ãã©ã³ããéåžžã«è€éã§ãããããåäžã®é¢æ°ã§èšè¿°ã§ããªãå Žåãè€æ°ã®é¢æ°ã®æ§æãšããŠèšè¿°ãäœæã§ããŸãã
Mtã®å©ããåããŠãéåæåŒã³åºãããã®å¿çãåŸ ã€ããšã«ãã£ãŠäžæãããã«ãŒããšæ¡ä»¶ä»ããžã£ã³ãããéåžžã®ã³ãŒããèšè¿°ãããšããšåãã·ã³ãã«ã§éŠŽæã¿ã®ãã圢åŒã§èª¬æã§ããŸãã 3ã€ã®ç¬ç«ãããã£ãã·ã¥ã§é çªã«å€ãæ€çŽ¢ãããšããŸãã
async chain void search ( int key )
{
for ( int i = 0 ; i < 3 ; i ++ ) {
async call search_cache ( key, i /* cache id */ )
gives int value ;
if ( value > 0 ) {
printf ( "VALUE: %d \n " , value ) ;
break ;
}
}
}
ãããã£ãŠãéåæåŠçãã§ãŒã³ã®å ŽåãMtã¯Cãšæ¯èŒããŠè¡šçŸåãšäœ¿ããããã®é£èºçãªåäžãå®çŸã§ããŸãã
3.泚é
泚éã¯ã泚éèªã䜿çšããè¿œå ã®ãµããŒãæ å ±ã®ã³ãŒãã®çŽ¹ä»ã§ãã åèªã«æ³šéãä»ããããšã¯ãconstããã³volatile修食åãç«ã€ãšããã§ããã°ã©ãã§ãããŸããŸããã 泚éãä»ããåèªã¯ãã¹ãŠãæåã$ãã§å§ãŸããŸãã äŸïŒ
int * $nonnull ptr ; // NULL
MyObject * $heap myobj ; //
Mtãã©ã³ã¹ã¬ãŒã¿ã¯ãè¿œå ã®ãã§ãã¯ã«æ³šéã䜿çšããéçã³ãŒãæ€èšŒã·ã¹ãã ã®åºç€ã§ããããŸãã
4. C ++æ©èœã®åçš
ãã©ã³ã¹ã¬ãŒã¿ã®å®è£ ã®èŠ³ç¹ããèŠããšãC ++ãšæ¯èŒããŠC ++ã®æãè€éãªæ©èœã¯ãåŒæ°ã®ããŒã¿åã«å¯Ÿããèšèªæ§é ã®æå³ã®äŸåæ§ã§ãã ããã¯ãŸããé¢æ°åã®ãªãŒããŒããŒãïŒæŒç®åã®ãªãŒããŒããŒããå«ãïŒã®ã«ãŒã«ãšãéšåçãªç¹æ®åãèæ ®ãããã³ãã¬ãŒãã®éžæã®ã«ãŒã«ã«é¢ä¿ããŸãã ãã®ãããªäŸåé¢ä¿ã¯ãæ³šå ¥ã§äœ¿çšãããé¢æ°ãŸãã¯ãã³ãã¬ãŒãã決å®ããããã«ãé¢æ°ãŸãã¯ãã³ãã¬ãŒããžã®ãã¹ãŠã®åŒæ°ã®ããŒã¿åãå°åºããå¿ èŠãããããšãæå³ããŸãã ããã«ã¯ãåå€æã«ãŒã«ãå®å šãã€æ£ç¢ºã«å®è£ ããå¿ èŠããããŸãã ããããã¹ãŠããããªãã®éã®äœæ¥ãæ§æããŠããŸãã
åæã«ãååã®ãªãŒããŒããŒãã¯ãèšèªã®ç©è°ãéžãããããã£ã§ãã ããšãã°ãGoèšèªã®äœæè ã¯ãFAQã«ææ矩ãªãšã³ããªããããããæåŠããŸãã ã
Mtã¯ãé¢æ°åãšæŒç®åã®ãªãŒããŒããŒããå€éç¶æ¿ãäŸå€ãRTTIããªãŒããŒããŒãããŸããã éšåçãªç¹æ®åã®ãªããã³ãã¬ãŒãã¯å®è£ ãããã»ã©é£ãããªããããã¯äžè¬åãããã³ã³ããã¯ã©ã¹ãäœæããã®ã«ååãªã®ã§ãèšèªã«ãã³ãã¬ãŒããå«ããããšã¯çã«ããªã£ãŠããŸãã ååã®ãªãŒããŒããŒãããªãå Žåããã³ãã¬ãŒãã¯ã¯ããã«åçŽã§ç°¡æœãªããŒã«ã«ãªããŸããC++ã®ãããªã¡ã¿ããã°ã©ãã³ã°æ©èœã¯ãããŸããã
5.ãªã³ã¯ãšåŒ±ããªã³ã¯
æŒç®åã®ãªãŒããŒããŒãããªããããstd :: auto_ptrãboost :: shared_ptrãªã©ãMtã«ãã¹ããŒããã€ã³ã¿ãŒãã®äŸ¿å©ãªé¡äŒŒç©ãå®è£ ããããšã¯ã§ããŸããã 代ããã«ããªã³ã¯ã«ãŠã³ãã¡ã«ããºã ãèšèªã¬ãã«ã§ææ¡ãããŠããŸãã
int @a ; //
int @@b ; //
åºæ¬ããŒãžã§ã³ã§ã¯ãåçŽãªåç §ã«ãŠã³ãã䜿çšããŸãã ãã«ãã€ã³ãªã³ã¯ã«ãŠã³ã¿ãŒ
ååæãŸãã¯éåæMtãªããžã§ã¯ãïŒãªããžã§ã¯ããšéåæãªããžã§ã¯ãïŒã«ã ãªã³ã¯ç®¡çã«å¯Ÿãããã®ã¢ãããŒãã§ã¯ãããã°ã©ãã¯ã¡ã¢ãªãªãŒã¯ã«ã€ãªãã埪ç°ãªã³ã¯ã®äœæãé¿ããå¿ èŠããããŸãã 匱ããªã³ã¯ã¯ãã«ãŒããäžæããããã«äœ¿çšãããŸãã å°æ¥çã«ã¯ãããè€éãªã¬ããŒãžã³ã¬ã¯ã¿ãŒã䜿çšããå¯èœæ§ãæ€èšã§ããŸãããä»ã§ã¯ãã®å¿ èŠæ§ã¯ããããŸããã
æŒç®åã®ãªãŒããŒããŒãããªãå ŽåãMtã§C ++ãªã³ã¯ïŒintããã³a圢åŒïŒããµããŒãããå¿ èŠã¯ãããŸããã
èšèªã¬ãã«ã§ãªã³ã¯ãå®è£ ãããšãC ++ãã³ãã¬ãŒãã§æ§ç¯ã§ãããããå®å šã§äŸ¿å©ãªã¡ã«ããºã ãååŸã§ããããšã«æ³šæããŠãã ããã
ãããã«
å±±ã«å«ããäºå®ã®äž»ãªæ©èœã®æŠèŠã説æããŸããã ãããã«å ããŠãéçºãç°¡çŽ åããããã°ã©ã ã®äºæ³ãšã©ãŒæ°ãæžããããšãç®çãšããéçºã®ä»ã®ã¢ã€ãã¢ããããŸãã
Mtèšèªç¿»èš³è ã¯ããªãŒãã³ãœãŒã¹ãããžã§ã¯ãã§ãã çŸåšãC ++èšèªããŒãµãŒã®ãµãã»ãããšããŠååšããsvnãªããžããªmync.svn.sourceforge.net/svnroot/mync/trunkã« ãscruffyããšããäœæ¥åã§ååšããŠããŸãã
C / C ++èšèªã®ç¹å®ã®ããããã£ãè¿œå ãŸãã¯å€æŽããããšã«ã€ããŠèããã¢ã€ãã¢ãããå Žåã¯ãããããçºå£°ããããšããå§ãããŸãïŒãããããããã®å®çšçãªãã¹ãã®æãæ¥ãŸããã
ãã®ãããžã§ã¯ãã«åå ããããšããå§ãããŸãã æ°ããç¥èãšçµéšãæäŸã§ããç¬ç«ããä»äºã®ãããã¯ãæ¢ããŠããå ŽåããããŠé«å質ã§æåãã補åã«æåããå Žåã¯ãæ°ããèšèªã³ã³ãã€ã©ãåªããéžæè¢ã«ãªããŸãã Mtãç®æããŠããåé¡ãããŸãé¢ä¿ãªãå Žåã¯ãC ++ããŒãµãŒãšC / C ++ããã°ã©ã ã®éçåæã·ã¹ãã ã®éçºã«èå³ããããããããŸããã
äžç·ã«ãã£ãšã§ããïŒ
ãæž èŽããããšãããããŸããã