COW copy on write linux ¿ª²©À²¡£¹þ¹þ
½ñÌì¿´LinuxµÄÄÚÈÝʱÕÒµ½µÄ¡£ µ«ÔËÐÐʱ·¢ÏÖcopyʱµØÖ·ÒѾ²»ÖµÏòͬһ¿éÄÚ´æÁË¡£ÎªÊ²Ã´ÄØ£¿£¿
STL±ê׼ģ°å¿âÖеÄstringÀ࣬ҲÊÇÒ»¸ö¾ßÓÐдʱ²Å¿½±´¼¼ÊõµÄÀà¡£C++ÔøÔÚÐÔÄÜÎÊÌâÉϱ»¹ã·ºµØÖÊÒɺÍÖ¸Ôð¹ý£¬ÎªÁËÌá¸ßÐÔÄÜ£¬STLÖеÄÐí¶àÀ඼²ÉÓÃÁËCopy-On-Write¼¼Êõ¡£Í¨³££¬stringÀàÖбØÓÐÒ»¸ö˽ÓгÉÔ±£¬ÆäÊÇÒ»¸öchar*£¬Óû§¼Ç¼´Ó¶ÑÉÏ·ÖÅäÄÚ´æµÄµØÖ·£¬ÆäÔÚ¹¹Ôìʱ·ÖÅäÄڴ棬ÔÚÎö¹¹Ê±ÊÍ·ÅÄÚ´æ¡£ÒòΪÊÇ´Ó¶ÑÉÏ·ÖÅäÄڴ棬ËùÒÔstringÀàÔÚά»¤Õâ¿éÄÚ´æÉÏÊǸñÍâСÐĵģ¬stringÀàÔÚ·µ»ØÕâ¿éÄÚ´æµØַʱ£¬Ö»·µ»Øconst char*£¬Ò²¾ÍÊÇÖ»¶ÁµÄ£¬Èç¹ûÄãҪд£¬ÄãÖ»ÄÜͨ¹ýstringÌṩµÄ·½·¨½øÐÐÊý¾ÝµÄ¸Äд¡£
main()
{
string str1 = "hello world";// string str1 ("hello world"); µ÷ÓõÄÊǹ¹Ô캯Êý
string str2 = str1; // string str2 (str1); µ÷ÓõÄÊÇ¿½±´¹¹Ô캯Êý
//´Ëʱstr1,str2¹²ÏíÄÚ´æ
printf ("Sharing the memory:\n");
printf ("\tstr1's address: %x\n", str1.c_str() );
printf ("\tstr2's address: %x\n", str2.c_str() );
str1[1]='q';
str2[1]='w';
/*µ±È»ÊÇÔÚ¹²Ïíͬһ¿éÄÚ´æµÄÀà·¢ÉúÄÚÈݸıäʱ£¬²Å»á·¢ÉúCopy-On-Write¡£±ÈÈçstringÀàµÄ[]¡¢=¡¢+=¡¢+¡¢²Ù×÷·û¸³Öµ£¬»¹ÓÐһЩstringÀàÖÐÖîÈçinsert¡¢replace¡¢appendµÈ³ÉÔ±º¯Êý¡£*/
printf ("After Copy-On-Write:\n");
printf ("\tstr1's address: %x\n", str1.c_str() );
printf ("\tstr2's address: %x\n", str2.c_str() );
return 0;
}
½á¹û£º
Sharing the memory:
str1's address: 12ff3c //·Ç343be9£¿£¿£¿
str2's address: 12ff14 //·Ç343be9
After Copy-On-Write:
str1's address: 3407a9
str2's address: 343be9
str1ºÍstr2´æ·ÅÊý¾ÝµÄµØÖ·ÊÇÒ»ÑùµÄ£¬¶øÔÚÐÞ¸ÄÄÚÈݺó£¬str1µÄµØÖ··¢ÉúÁ˱仯£¬¶østr2µÄµØÖ·»¹ÊÇÔÀ´µÄ¡£´ÓÕâ¸öÀý×Ó£¬ÎÒÃÇ¿ÉÒÔ¿´µ½stringÀàµÄCopy-On-Write¼¼Êõ¡£
ÒýÓüÆÊý¾ÍÊÇstringÀàÖÐдʱ²Å¿½±´µÄÔÀí£¬RefCnt±íʾʹÓù²ÏíÄÚ´æ¸ö¶ÔÏó¸öÊý¡£µ±¹²ÏíÄÚ´æ±»Ð޸ĵÄʱºò£¬²ÉÓÃÏÂÃ
Ïà¹ØÎĵµ£º
1. HCI²ãÐÒé¸ÅÊö£º
HCIÌṩһÌ×ͳһµÄ·½·¨À´·ÃÎÊBluetoothµ×²ã¡£ÈçͼËùʾ£º
´ÓͼÉÏ¿ÉÒÔ¿´³ö£¬Host Controller Interface(HCI) ¾ÍÊÇÓÃÀ´¹µÍ¨HostºÍModule¡£Hostͨ³£¾ÍÊÇPC£¬ ModuleÔòÊÇÒÔ¸÷ÖÖÎïÀíÁ¬½ÓÐÎʽ£¨USB,serial,pc-cardµÈ£©Á¬½Óµ½PCÉϵÄbluetooth Dongle¡£
ÔÚHostÕâÒ»¶Ë£ºapplication,SDP,L2capµÈÐÒé ......
Service Discovery Protocol(SDP)ÌṩһÖÖÄÜÁ¦£¬ÈÃÓ¦ÓóÌÐòÓз½·¨·¢ÏÖÄÄÖÖ·þÎñ¿ÉÓÃÒÔ¼°ÕâÖÖ·þÎñµÄÌØÐÔ¡£
·þÎñ·¢ÏÖÐÒé(SDP»òBluetooth SDP)ÔÚÀ¶ÑÀÐÒéÕ»ÖжÔÀ¶ÑÀ»·¾³ÖеÄÓ¦ÓóÌÐòÓÐÌØÊâµÄº¬Ò⣬·¢ÏÖÄĸö·þÎñÊÇ¿ÉÓõĺÍÈ·¶¨ÕâЩ¿ÉÓ÷þÎñµÄÌØÕ÷¡£SDP¶¨ÒåÁËbluetooth client·¢ÏÖ¿ÉÓÃbluetooth server·þÎñºÍËüÃǵÄÌØÕ÷µÄ·½·¨¡£ ......
1.¸ÅÄîºÍÇø±ð£º
¾²Ì¬¿â¾ÍÊÇÔÚ±àÒë¹ý³ÌÖÐһЩĿ±êÎļþµÄ¼¯ºÏ¡£¾²Ì¬¿âÔÚ³ÌÐòÁ´½ÓµÄʱºòʹÓã¬Á´½ÓÆ÷»á½«³ÌÐòÖÐʹÓõ½º¯ÊýµÄ´úÂë´Ó¿âÎļþÖп½±´µ½Ó¦ÓóÌÐòÖС£Ò»µ©Á´½ÓÍê³É£¬ÔÚÖ´ÐгÌÐòµÄʱºò¾Í²»ÐèÒª¾²Ì¬¿âÁË¡£
ÓÉÓÚÿ¸öʹÓþ²Ì¬¿âµÄÓ¦ÓóÌÐò¶¼ÐèÒª¿½±´ËùÓú¯ÊýµÄ´úÂë£¬Ë ......
Ò»¡¢TCPÁ¬½Ó¹Ø±ÕµÄ¼¸ÖÖ·½Ê½£º
1¡¢“Õý³£”¹Ø±Õ£ºµ÷ÓÃclose()¹Ø±Õsocket¡¢Ã»closeµ«½ø³ÌÕý³£½áÊø(µ±È»ÕâÊDz»Ó¦¸ÃµÄ×ö·¨)¡¢½ø³Ìcoreµô¡¢ÔÚshellÃüÁîÐÐÖÐkillµô½ø³Ì£¬¶¼¿É³éÏó³É“Õý³£”¹Ø±Õ¡£ÒòΪ¼´Ê¹coreµô£¬ÄÚºËÒ²»áÂíÉÏ°ïÓ¦ÓóÌÐò»ØÊÕ(close)socketÎļþÃèÊö·û¡£
“Õý ......