C++博客-markqian86 http://www.598club.com/markqian86/practice makes perfect???????????????????????1?????????????zh-cnMon, 20 Jan 2020 19:18:15 GMTMon, 20 Jan 2020 19:18:15 GMT60C++博客-markqian86 http://www.598club.com/markqian86/archive/2020/01/16/217089.html?????????????????

3.3.1???'1??

江苏快三开奖结果??1?o????'1??????'???????????????o??????o???????????????????a???'1???????????'1???????????????a???'1?????'1????????a????????????????????????????o????????????a???'1?????'1????????a??????????????????a?1?????????????????'1??? ???????????disruptor.strat()??1?3???-????????????????????'1???o???????-???????????????'1????????'1????-???????a???????|?????????3?3????????a????????????'1?????o???????o|???????????????a????????a???'1???????????'1???o|???????? 1.??1???'1?????o??????????????????aNext???CAS?????????????????1?a????'1???o|?????????????????????o|??? 2.??o?a???3?????????RingBuffer???Next??????????????????3???????????????3???next????????????????3??????Next?????????a????'?????????-?????????3?????????|????:

  • ????????o????1RingBuffer?????????????????
  • ????-????????|???o????|???3????????????
  • ?|??????o?????????????a???????2???????o????????????????o?????
  • ?|???????o?????????2?????????????a?????????????????-??????-???????????????????????????o??????o???????????????? 3.??1????a??????????????????a?????????o?????3??????????????????????-??????????|?????o??????????7??????????????3???????|???????'1???2??????8???10????a?o????????????????????????o??????????9????a?????????2??????????????????????o????????-?????????10?????????9??????????????????????????????????????????????????????8???
    4.?|??????????????o??1?????????????next|?????????????-??a?????3???? 5.?o???handler.onEvent()?????

???????????????????a????-??????????|???3?next=8????a????????? 1.|?????????o???????????????o|8?????????????????????????o|7 2.????8??????????????????????????????1?????????????-?????????????????????????????????o?????o??????o?o?8???9???10????????????????????10???????????????-??????|??????????avaliableBuffer??????1????o???? 3.???????o???handler????????????

 

4.Log4j??-???Disruptor

江苏快三开奖结果????????????????o?Log4j?????Disruptor,ArrayBlockingQueue??????????-????Log4j?????????????1??????????????????????o?Disruptor???????o??????????????????????????'?????????????????o?Disruptor?????????????????????o????

 

 


???????????????????
????????http://juejin.im/post/5b5f10d65188251ad06b78e3
????o?????????
???????????????????????????????????????3?????????????????????????????????3?????o?????

?????????????? 2020-01-16 20:12 ???????o
]]>
C++博客-markqian86 http://www.598club.com/markqian86/archive/2020/01/16/217088.html????????????????????????????Thu, 16 Jan 2020 08:32:00 GMThttp://www.598club.com/markqian86/archive/2020/01/16/217088.htmlhttp://www.598club.com/markqian86/comments/217088.htmlhttp://www.598club.com/markqian86/archive/2020/01/16/217088.html#Feedback0http://www.598club.com/markqian86/comments/commentRss/217088.htmlhttp://www.598club.com/markqian86/services/trackbacks/217088.html?????????????????linux?????????????????????, ??????o|???p43
?-???????????????linux?????????????????????, ??????o|???p50
epoll?o????????a?????+???a????????mutex+?o???????????
??????3?????????????????????->?????+rpc->??????????????? ???????'???????????????o?????-?1s??????????????a???????????????????????????o???????????o???????????????????
ECS????????word=system+entity; system=sys1+sys2+sysn; entity=componentN;

?????????????? 2020-01-16 16:32 ???????o
]]>
C++博客-markqian86 http://www.598club.com/markqian86/archive/2020/01/13/217085.html????????????????????????????Mon, 13 Jan 2020 03:28:00 GMThttp://www.598club.com/markqian86/archive/2020/01/13/217085.htmlhttp://www.598club.com/markqian86/comments/217085.htmlhttp://www.598club.com/markqian86/archive/2020/01/13/217085.html#Feedback0http://www.598club.com/markqian86/comments/commentRss/217085.htmlhttp://www.598club.com/markqian86/services/trackbacks/217085.html?????????

?????????????? 2020-01-13 11:28 ???????o
]]>
C++博客-markqian86 http://www.598club.com/markqian86/archive/2020/01/13/217084.html????????????????????????????Mon, 13 Jan 2020 03:22:00 GMThttp://www.598club.com/markqian86/archive/2020/01/13/217084.htmlhttp://www.598club.com/markqian86/comments/217084.htmlhttp://www.598club.com/markqian86/archive/2020/01/13/217084.html#Feedback0http://www.598club.com/markqian86/comments/commentRss/217084.htmlhttp://www.598club.com/markqian86/services/trackbacks/217084.html?????????

?????????????? 2020-01-13 11:22 ???????o
]]>
C++博客-markqian86 http://www.598club.com/markqian86/archive/2020/01/09/217073.html????????????????????????????Thu, 09 Jan 2020 08:54:00 GMThttp://www.598club.com/markqian86/archive/2020/01/09/217073.htmlhttp://www.598club.com/markqian86/comments/217073.htmlhttp://www.598club.com/markqian86/archive/2020/01/09/217073.html#Feedback0http://www.598club.com/markqian86/comments/commentRss/217073.htmlhttp://www.598club.com/markqian86/services/trackbacks/217073.html????

?-?????1???????????????-|C?-????????|??????????a?|????????????????o?????1?????-?????1???????1??????????????????1??????o????1?|??-?????1?????????-?????1????1??????????????????1?????o???????????????????????????-?????1????????o??o????

????1?????-?????1??

???????o??-????-?????????o?????????????-??????byte??????????o???????2??????????????????????????????????o????????????????????????????????????????o?1??????-???????????????-????????????2,4,???8??? ?????????-??????????????????-?????|??-????????????1??o????????????????????3???????????o????o???????????3???????????????????2???4???8??????????????1??|????????????????????????????????????????o?'????????????????????1?????

??1???????????????1?

??????????'????-?????1????????????????????

  • ?????????????????|?????????????????1???-?????????????'????
  • ??????????????a???????????1?????????|?????????????????????????????????'?????????|????????3?????1????????a?????????????-??????????3???
  • ????????????????????o???????????1???-?????????????'?????????|????????3????????????????-??????????3???

???????????????a??????-?????'???????|??????1????????
江苏快三开奖结果???????????????o?

/*================================================================ *   Copyright (C) 2018  Ltd. All rights reserved. *    *   ?????????????testByteAlign.c *   ??? ??o ?????shouwang *   ?????o?????????2018?1'09???15??? *   ???    ???? * ================================================================*/ #include<stdio.h> #include<stdint.h> struct test {     int a;     char b;     int c;     short d; }; int main(int argc,char *argv) {     /*??32??????64????????o????????size_t????????????*/     printf("the size of struct test is %zu\n",sizeof(struct test));     return 0; } 

江苏快三开奖结果????????32??????o??1???????????????-????a?????1???????????????????????????????test ????????o16?-??????????????11?-??????a???4?-??????b???1?-??????c???4?-??????d???2?-??????

#64?????o??????????32??????o????????|???????????a?o? #sudo apt-get install gcc-multilib gcc -m32 -o testByteAlign testByteAlign.c #????????o? chmod +x testByteAlign  #??????????? ./testByteAlign  #???? the size of struct test is 16 

????????????????????test???????????????-???-???????????????????????????????????????o??????????
江苏快三开奖结果??a??1?????:

江苏快三开奖结果0~345~910~11abcd

??1?????:

0~345~78~1112~1314~15ab???????????1cd???????????1

???????????????????o???c??????????o5??????????3??1??|????????????????????o?????????sizeof???int????????'???????????-??b????????????o?3??a?-????????????c??????????o8?????b?????????????????d?2???????3??1??|????o??????o????1?????????|????????-???????????????'?????o????1???|?????3?????????????????????
?????????????????

struct teArray[2]; 

江苏快三开奖结果???????????????????teArray[0]???d?|??????????????-?????????1?teArray[1]???a???????o14??????????3??1??|??????????-d??????1???|????????-??????

??o????1?|??-?????1??

????o??????????|??1?????????????????o??????????-????????????????????????????????????????????????test????????a??|?11?-????????o?'???????????'??????o?16?-?????????????????a'1?o???o?'??????1???o????1???|??????-?????1?????????????|????????????????????-??3????????
????????????1??'????????????o????????????????a?-?????????????|????????????????o?????????????-???-???8??a?-???????|?????????adouble???????????????1?????8??????????????1??????a????-??????????????????????????????????|????????adouble??????????????2??????1???????????????????????????a8?-????????-??????1??????????????|??????????????-?????????????????????????????????????????????????????????????????????????????|??-?????1??????????????-??3???????????
江苏快三开奖结果??????o??????????-????|??????|???a??1??????????????????????????-?????????????3crash????????????????????o???

????????????-???????

江苏快三开奖结果????????????-?????1????????????????????????????????????????????|???1????????-????????1?????????1?????????3??????????????|???3?3?-?????1????????????

??o?'?-???

??????????????????????????test?????????????o?'?????o16?-?????????????|?????????????????????????1?????????'?????????o?o???????????????o????????????????????????test??????????o12?-???

struct test {     int a;     char b;     short d;     int c; }; 

??o?'?-??????????|????,b???c?-??????o??????a?-????????-:

0~3456~78~11ab???????????1cd

江苏快三开奖结果?1??????'????|???????????????????????????????????????????'????????????????????????????????-?????o?'???

跨?13???????

江苏快三开奖结果???o????????13????1????1??????????????????|??-???????????????????????????????????13????????????????????????????????????????????????o????????????????????????o?????1???????3?????????????????????????-?????o?o???????????????1??'?????-?????????????????????????????????????????????????1?3????

  • 1?-?????1??
  • ?a???1???????????-?????????

???????????????????a?????#pragma pack(n)???n??o?-?????1???????????????????????'????-?????1?????
???????????????????o?????|???????????????test????????????????a??????????3?|????:

#pragma pack(1) /*1?-?????1??*/ struct test {     int a;     char b;     int c;     short d; }; #pragma pack()/*??????????1??*/ 

???????????????????????????13???????????test??????????o11?-??????????????????????跨?13??????????????????'?????????????????o???o?'??????????1????????????????o??????????

江苏快三开奖结果???????o???1?o??????a????????????gcc??????|?????????1?3??????????1?-?????1??

struct test {     int a;     char b;     int c;     short d; }__attribute__ ((packed)); 

?3:

  • __attribute__((aligned (n)))??????????????????????????????1????n?-????a????1??????????|????????????-???????????????o|??o?n???????????????????????????o|?????1?????
  • __attribute__ ((packed))????????????????????????????-???????????1??????1??????????o???1?-?????1?????

??o?????????1?-?????1??????????????????oo??o??????????????3test???????????????|????:

struct test {     int a;     char b;     char reserve[3];     int c;     short d;     char reserve1[2]; }; 

???????????????????1???????????o?'???????????????????????????????????|????????-?????1???????????????????|???????????-?????????????????????????????

??????

????????????????|????????3????-?????1????????????????????|?????????3?3?-?????1?????????????????????????????-???????????????????3??????????????-????1?-?????1????????????o??????????????o?????

  • ??????????????????????????????????????????????o?'
  • 跨?13????????????????????1?-?????1????????????o?'??????????????????
  • 跨?13??????????????oo??o?????-????????????????????????????????????????o?'
  • ???????????????????1???????????????????????


?????????????? 2020-01-09 16:54 ???????o
]]>
C++博客-markqian86 http://www.598club.com/markqian86/archive/2019/12/25/217047.html????????????????????????????Wed, 25 Dec 2019 07:36:00 GMThttp://www.598club.com/markqian86/archive/2019/12/25/217047.htmlhttp://www.598club.com/markqian86/comments/217047.htmlhttp://www.598club.com/markqian86/archive/2019/12/25/217047.html#Feedback0http://www.598club.com/markqian86/comments/commentRss/217047.htmlhttp://www.598club.com/markqian86/services/trackbacks/217047.htmlLinux ????????????-???????????????a??3???|??????? 
1????????a??????????????????????????????o?'?????????????????????????1???????????-?????????????????? 
2?????????????????????????a?????????????(???????a?????????????????????????o?')??????????????????????????????????-??????????????? 
3????|????????????????1?o???????????????????????????-???-???????o?????o????-??-???????-????????????????????????????'????????????????|?????-?????????????-??2????????????1???????-???????????3?????????????3??????????????-??? 
   
??o?o??????????????????o??|?????????????
??????Linux ????????????o?'?|?????????????
Linux ?????????????????o?'????????????o????????????????o?'??????????????????????????????o??? 
1?????a????????????????o?'??a???????????????????(?????????????????????rodata ???(C??????-???|??2???#define????1?????????) )
2??????????????????-????????????????????????????o?'??? 
3?????? ????????13???????'????????????-???? malloc/new ???????????o??o??-????????-?????????????????????????? brk ??? sbrk ????????????'??? 
4????????????????o??? ????|???????o???????o?????-??-??????????????o?'???????-???????????? mmap ????????????????????????????o?'??? 
5????????????o???'????????????????????????o?'??????????o 8M ?????????? ulimit –s ????????? 
6????????????????o?'???????????????????????????-???o????????????????????(?????-???????????????????o?')???
????????? 32 ????3?????????????????????????o?'??????(????a??????????????????o?3???????)???
32 ????3???????4G ??????????o?'::
      ?????- 0x08048000~0xbfffffff ?????????o?'???0xc0000000~0xffffffff ???????????o?'????????????????????????????????????????????3??????????????????|????????????????????-??????|?????%esp ?????????????????????????1????????????brk/sbrk ???????????????_edata????????????1????????????
64????3????????????????????? 64 ????3?????????|?????? 2^64 ??????????o?'?????? 
?o?????????? 64 ????3???????????????????o?'?????????????o???1?????? 
1??????????o?'?????????2^32????1???????2^64?????????????2^48????????o?1??????|? 2^64 ???1?????????????o?'????????o?'??a???????'???o??????a'1???64???Linux??????????48????????o????????????o?'???40?????o??????????????
????????? /proc/cpuinfo ????????? 
address sizes   : 40 bits physical, 48 bits virtual 
2????????-???0x0000000000000000~0x00007fffffffffff ??o??????o?'??? 0xFFFF800000000000~ 0xFFFFFFFFFFFFFFFF ??o????????o?'??????????? 256TB(2^48) ???????????o?'???
??????a??o?'?????1??1????????? 47 ?????? 48~63 ?????????????????o??????o 0 ??o??????o?'?????|?????o????????o?'??? 
3?????????o?'??????????????????????????????a??????????????????????????????????????o????????????
 
?o????malloc???free????|?????????????????????-????
?|??????????????????????o????-??-???????????
         ??ps -o majflt,minflt -C program??????????????
          majflt????major fault?????-?????????????????minflt????minor fault?????-??????????????????
          ??????a???????o?????a?????a?????????????????????????o????-??-???????????
????????o????-??-???????????o????o??????????
????????a????????????o????-??-?????????????????????????????????????????????????????? 
1?????????|???????????????????????|????3? 
2?????????/??????????a???????? 
3??????????????????????1????????????????????????'??????0????????????1?????12??? 
4?????o??????????3?3?????????????????????????????? 
????????????????o????-??-????????????? 
?|???????3?-??????|??????????????????1????????o????-??-????majflt?????|???????minflt??? 
????-???????????????
??????????3??????o|??????????????????????-??????????1??????????????????a?3????????????????brk???mmap?????????????o?????-???????
1???brk?????????????(.data)??????????????????_edata???????????????
2???mmap????????????????????????o?'??-??????????????-?'??????o?????????????o??????????1??????????????o?2????????????-????
     ????????1?????????????????????????-?????2???????????????????-????????????????????2????????????????????o?'????????????????????o????-??-??????????3????'?'????????????????-????????????o????????????-??????????????-??1??'??????????3?3????
????????C?o???-??????????o?malloc/free???????????????????-??????????a??????o????????brk???mmap???munmap???o??3??????????????????
?????????????a????-?????'???????-??????????????????
????????????malloc???o?128k???????-?????????brk?????????-??????_edata????????????(??a????????????o?'????????1?o???????????-?(????-?2????????????)??????????????/??????????????????????????o????-??-???????????????????1?o??????????????-??????????????????????o?'??o??????????3?3?)????|??????????
1??????????????????????????????????????????-???o?'??????????????|????1????o???
      ?????-???mmap????-???????????????????????????????-?'???????|?libc-2.2.93.so?????????????????????-?????????o?o???????????????????o?????-???????????????
      _edata????????glibc????????1?????????????????????????????????? 
2??????????A=malloc(30K)?????????????-???o?'?|????2???
      malloc???????????brk?3????????????_edata?????????????????30K???????????????????-?????????
      ??????????????????a|????_edata+30K???????????-???????o????
      ?o?????????????????_edata+30K??a??????????????????????????????A?????????-???????????2????????????????1???1?o????????-?????????????????????A?????????-?????????????????????o????-??-???????a???????????????????????A?????????-???1?o????????????????1??????'????|??????malloc??????o?A??????????1???????????????????????????????1????A??1?o?????????????????????????????????? 
3??????????B=malloc(40K)?????????????-???o?'?|????3???
???????o????malloc??o?128k???????-?????????mmap?????????-????????????????1??'???????????o?2????-??????(??1?o???????????-???????????????????o0)????|??????????
4??????????C=malloc(200K)?????????????-???o?'?|????4???
      ???????????????malloc??????????????-?????|???????????-???o?128K????????M_MMAP_THRESHOLD???1???????????????????????_edata??????o??????????????mmap?3???????????????????????????-?'????????????????????-????
      ?????-???????|?????????o::
      brk????????????-???|??-??????????????-?????????????????????????????|??????B??????1???????A????????????????????????????????-????????o???????????????????1????????'???????????????????mmap????????????-?????????????????????
      ????????????????????????????????1??????????????????????????????????'?????????-|????????????glibc????malloc??????????o???? 
5??????????D=malloc(100K)?????????????-???o?'?|????5???
6??????????free(C)?????????C??1?o?????????????-??????????????-?????????????
7??????????free(B)??????????|????7????o???
        B??1?o?????????????-??????????????-????2?????????????????o??a????????a_edata?????????|??????????????????1?D?????????-?????1??????????
?????????B?????????-????????????????????????|????????a?????????????????a40K????????????1?malloc????????????B?????????-?????????????o???? 
8??????????free(D)??????????|????8????o???
        B???D????????????????????????140K?????o?2????-????
9??????????????????
       ???????????????o?'?????o?2????-?????128K????????M_TRIM_THRESHOLD???1????????????????????-??'????????????trim????????????????a?-?afree?????????????????????????????o?2????-?????128K????o????????-??'???????????????9????o???
??????????????????????-?brk???sbrk???????'?????????????o????1???????????? mmap ???????????munmap??'?????????????? 
        ?????????????????????????'???????????????'??????“????-??3??2”?????????o????1? malloc ??????????? mmap ???????????(mmap????????????-?????????????? munmap ???? free ????????????-??????)????????????????1?o???o? 128k ???????????-????????? mmap ??? 
        ???????????????? OS ??3????????????????o?'????????? sbrk/mmap/munmap ??????3?????????????1?????3????????????????????3???????o????????1??????? mmap ??3????????-??? munmap ????????????3?????o?????'???????o????-??-???????|?????? mmap ????? 1M ??o?'????????????????o????o??????o????-??- (1M/4K ??? ) ??????munmap ?????????????? 1M ??o?'?????????????o????????o????-??-?????o????-??-?????????????o??????????'?????????CPU?????????????|??????|????????? mmap ???????????-???????????'???????o?'???????????'????????????????????'??????'????
        ?????????????????a????-??o?'????1???????????????????o??2????????? OS ????|????????????????????????????????????-???????????????o??????????3????????????o????-??-?????????????? CPU ??????????? ????-??? glibc ??? malloc ???????-??????????????o? sbrk ??? mmap ????o???????????????????o??1???????????????????-? (128k) ???????? mmap ???????????o?'????1???????? mallopt(M_MMAP_THRESHOLD, <SIZE>) ????????1????a??'?????????
 
???????|???????????????????o????-??-????????? 
??????????????????????????o????-??-?????? 
ps -o majflt,minflt -C <program_name> 
ps -o majflt,minflt -p <pid> 
?????-:: majflt ???? major fault ??????????????
           minflt ???? minor fault ???????????????
??????a???????o?????a?????a?????????????????????????o????-??-???????????
?????- majflt ??? minflt ????????????::
        majflt ??o??|???????????????????????????-???1?o???????????????-??|?load ????????????-???-????1??????????-?????????????-?????3?????|???????????????????3????????-???
?o????C?-????????-????????1??????malloc
  
C?-??????-????????1???
???1??? ?????????-?????o???????????????-??????o?????????????????2???????????????????????-??????o??????'??a????????'???-??????????|?????????????static????????
???2??? ?????????????o????????????????????????????????????????-??????????????????????????????o????????????????????????o??-??????????a???????????????????-????????
??????????o????????????????????-???????????????????????????????????-???1??????????
???3?????????????????????o|??????????-????????????o??????????????????malloc???new??3??????????????????-???????o?????a?'?'???????????free???delete?????????-?????????????-????????-??????????????3????????????????????'????????????1??????
     
      C?-??????-???3??????3???????????|???? alloc,calloc,malloc,free,realloc,sbrk?-?.?????-alloc???????????3?????-?,????-??????????. malloc????????????-????????o??????-???,?1?????2????????????????-?????????1,????-??o??????malloc?1????,????????memset????????????????????????-???o?'.calloc??????????????????????????-?,???????o0. ??realloc?????1malloc??3????????-??????????????'.??3????????-?????????|??????????free????????. ??sbrk??????????????????????????;
       malloc/calloc/free??o???????????C??????o?????????,?OS?????3.C??????o???????????????????????????????-???????????????????????-?.?|???????o? malloc??????????o?o??o??????????-??????o?',???1???|???????brk?3???????????????????????o?',????????????????o?'.free???,????????????-??1?????????3????????os, ?????????????????????????-. ???????????a?????1: brk??????o???1???,??????????????OS??3?????????-?,??malloc?-???????????????o??????,????3???o???????????|???.???????o?????????o??????2.
????????????o????????????: ?3??????????????????????????????????-??????(???????3?????????a????????o???????????????????????????-???3?,?????????,??1?o???????-???????????????????a'1; ?3?????????3?????-?????????'?,???????????????????????????????????.
?????malloc()???calloc()???????????????????????????-???o?'?????????????????o??????
      ??Linux?3?????????????o????????????-???????????????o???????????????o?'??o????o???????????????????????????????????????????????????????????1??'?????o?2??o??????o??????????-?????????
      ?????????????????mm_struct??-??????????????start_code???end_code?????????????????????????????-?????????start_data??? end_data????????????????????????????-?????????start_stack???????????????????????????start_brk????????????????-?????????????????????????? ?????????????????????a brk?????????????????????????????????????????????-???????????????????-?????????
C?-?????????????-????????o???????????malloc()?????Linux????????o????????????????????????brk?3??????????brk()????????a???????????????3????????????a?????????????1???mm_struct????????????????????brk?????????
      mmap?3?????????????o???'?????????????????-???????????????????????????a??????????????????????????????1?????????????o?'??-??????????????????????????????????o??????????-??????????????? linux/mm/mmap.c?????????do_mmap_pgoff()???????????mmap?3????????????????????????do_mmap_pgoff()??????????????a???????o?o??????avm_area_struct??????????1????file????????????????????????????????????m_file????1??2??????????????????1??????????????-????
Linux????-????????????o????????3?1????????????a?????????-??????????a???????????????????o???????a??????????????????????
————————————————
??????????????????????oCSDN?????????gfgdsg?????????????????????????a CC 4.0 BY-SA ????????????????????????????????o?????????????????????
??????????????http://blog.csdn.net/gfgdsg/article/details/42709943


?????????????? 2019-12-25 15:36 ???????o
]]>
C++博客-markqian86 http://www.598club.com/markqian86/archive/2019/12/25/217046.html????????????????????????????Wed, 25 Dec 2019 07:25:00 GMThttp://www.598club.com/markqian86/archive/2019/12/25/217046.htmlhttp://www.598club.com/markqian86/comments/217046.htmlhttp://www.598club.com/markqian86/archive/2019/12/25/217046.html#Feedback0http://www.598club.com/markqian86/comments/commentRss/217046.htmlhttp://www.598club.com/markqian86/services/trackbacks/217046.html?????????

?????????????? 2019-12-25 15:25 ???????o
]]>
C++博客-markqian86 http://www.598club.com/markqian86/archive/2019/12/19/217039.html?????????????? VC++???????????????????1???????????????????????|????????????????????o?????????o???????????a??|???????????????|???????????????1?o?????????????????????????????'????|??????1??????o????????????????????1?o?????????????????1????????????|??????????-??????????????????????????????????????a????????????????????|???1???????????????????????????o?????o???????1?????????????|???????o???????????|????o?????a??????????windows??????????????????o???????API??????????????o??????a??|????API??3???

??????'???

SymInitialize???????a????????|???????????????????3????????? SymCleanup?????????????a????????????????3??????????????SymInitialize?1??????|????SymCleanup???????????????o?????????? StackWalk??????o????????????|???????a???????????????????????????????????????????????????????????????????????a?????????????????????????|???????

BOOL WINAPI StackWalk(   __in          DWORD MachineType, //??o???????????????????intel???x86?3???????????a????????????IMAGE_FILE_MACHINE_I386   __in          HANDLE hProcess, //???a?????????????   __in          HANDLE hThread, //???a????o?????????   __in_out      LPSTACKFRAME StackFrame, //??????????a?????????????????   __in_out      PVOID ContextRecord, //??????????????o?????????   __in          PREAD_PROCESS_MEMORY_ROUTINE ReadMemoryRoutine,   __in          PFUNCTION_TABLE_ACCESS_ROUTINE FunctionTableAccessRoutine,   __in          PGET_MODULE_BASE_ROUTINE GetModuleBaseRoutine,   __in          PTRANSLATE_ADDRESS_ROUTINE TranslateAddress //?????????????a????????????????????????????3?????a????????????????o???????????????1????????????a??|???????????o????????????? );

??|??3???????????1????????|???????????????????|???1StackFrame??-???AddrPC???AddrFrame???AddrStack???????a????????????????????????????????3?????????????????????-???o?????????????????????????'??????|??????????????'??????????|??????????????MSDN???

SymGetSymFromAddr?????1?????????????????????????????????????????????????-??????????????a???????????????|??????? BOOL WINAPI SymGetSymFromAddr(   __in          HANDLE hProcess, //??????????   __in          DWORD Address, //??????????   __out         PDWORD Displacement, //?????????|??????????????????????????NULL???????????-???   __out         PIMAGEHLP_SYMBOL Symbol//????????????????? );

SymGetLineFromAddr?????1??????????????????????????????????????????3????????????|????????????a??a???????????a??????o?????????????????????????????????

BOOL WINAPI SymGetLineFromAddr(   __in          HANDLE hProcess,   __in          DWORD dwAddr,   __out         PDWORD pdwDisplacement,   __out         PIMAGEHLP_LINE Line );

???????????????1????SymGetSymFromAddr???????????? ???????????1?????????'????????????????????????????o?o????a????????????|??????????????'?-?a?|??????? 1. |????????????SymInitialize?????????3??????????????????? 2. ???????????????StackFrame????????3???????????????????????????????a??? 3. ??a??????StackWalk?????????????????????????????????????'???a??????????? 4. ????????????????????????????????SymGetSymFromAddr???SymGetLineFromAddr?????????????????|????????? 5. ???SymCleanup????????????a ????????|??3???????????1???????????StackWalk????o????o???????????????????????|??????????1????????????a??????2?????????o??????????????????????????????1??????StackWalk?a????????????a??????????????????

??????????

void InitTrack() {     g_hHandle = GetCurrentProcess();      SymInitialize(g_hHandle, NULL, TRUE); }  void StackTrack() {     g_hThread = GetCurrentThread();     STACKFRAME sf = { 0 };      sf.AddrPC.Offset = g_context.Eip;     sf.AddrPC.Mode = AddrModeFlat;      sf.AddrFrame.Offset = g_context.Ebp;     sf.AddrFrame.Mode = AddrModeFlat;      sf.AddrStack.Offset = g_context.Esp;     sf.AddrStack.Mode = AddrModeFlat;      typedef struct tag_SYMBOL_INFO     {         IMAGEHLP_SYMBOL symInfo;         TCHAR szBuffer[MAX_PATH];     } SYMBOL_INFO, *LPSYMBOL_INFO;      DWORD dwDisplament = 0;     SYMBOL_INFO stack_info = { 0 };     PIMAGEHLP_SYMBOL pSym = (PIMAGEHLP_SYMBOL)&stack_info;     pSym->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL);     pSym->MaxNameLength = sizeof(SYMBOL_INFO) - offsetof(SYMBOL_INFO, symInfo.Name);     IMAGEHLP_LINE ImageLine = { 0 };     ImageLine.SizeOfStruct = sizeof(IMAGEHLP_LINE);      while (StackWalk(IMAGE_FILE_MACHINE_I386, g_hHandle, g_hThread, &sf, &g_context, NULL, SymFunctionTableAccess, SymGetModuleBase, NULL))     {         SymGetSymFromAddr(g_hHandle, sf.AddrPC.Offset, &dwDisplament, pSym);         SymGetLineFromAddr(g_hHandle, sf.AddrPC.Offset, &dwDisplament, &ImageLine);         printf("?????????????? : %08x+%s(FILE[%s]LINE[%d])\n", pSym->Address, pSym->Name, ImageLine.FileName, ImageLine.LineNumber);     }  }  void UninitTrack() {     SymCleanup(g_hHandle); }

江苏快三开奖结果????????o??|???????

void func1() {     OPEN_STACK_TRACK; }  void func2() {     func1(); }  void func3() {     func2();  } void func4() {     printf("hello\n"); }  int _tmain(int argc, TCHAR* argv[]) {     func4();     func3();     func3();     return 0; }

OPEN_STACK_TRACK????????a????????????????1??|???????

#define OPEN_STACK_TRACK\  HANDLE hThread = GetCurrentThread();\ GetThreadContext(hThread, &g_context);\ __asm{call $ + 5}\ __asm{pop eax}\ __asm{mov g_context.Eip, eax}\ __asm{mov g_context.Ebp, ebp}\ __asm{mov g_context.Esp, esp}\ InitTrack();\ StackTrack();\ UninitTrack();

????a???o???|??3??????????????1??? 1. ?|??????3|????a??????????????????????|???????a????????????????????????????????????????????????-????1????????????????????????????-????????????????????????????????????????????????o????a??a???????????????????????2????????????????????????????????????????o??????????????????????????o????o???????o?o??????????????????????????????????? 2. IMAGEHLP_SYMBOL??????????????-??3?o?Name??????????????a????????a?-?????????????SymGetSymFromAddr??????????????????2??????3???????a????????????????a??????????????????????????????o??????2??o?o???o??????????????o?o??????????????|???Name?????????????????????????????2??o?????????????????????????1???????????????1?????a?????????SYMBOL_INFO??????????????|??IMAGEHLP_SYMBOL??-???MaxNameLength????????????Name??????????o|?????|???1?????????????????2??o??????????????? 3. ???????????o???????????????????a???func4?2??????????????????????????????o???????????????????g_context????????GetThreadContext????1???????????-?????????????????????????-????????????GetThreadContext????????????????|??????3??????????a???????????a??|??????1??????????????????????????????StackWalk?????1????????????????a??????1???a??|??????1??1?o??????????????????3????????|??????1eip ???ebp???esp???????????3?o?esp ebp?????????????????1?????????????1?o????????-esp ebp???o?????-??????????????eip?????????????1??????????????????????mov??????????eip??????????1?????????????????1???eip????????????????????????????eip???????????????????????????????????call???????????????-???????eip?????????????????????????????????????-?????o???call???????????'??? push eip???jmp addr??????????????????1????????????|????????????call?????????????o5??a?-????????????call $ + 5??o???????-?eip??3????????????????3???????????????????????????????????????????GetThreadContext??-????????3????????



?????????????? 2019-12-19 12:39 ???????o
]]>
C++博客-markqian86 http://www.598club.com/markqian86/archive/2019/12/19/217038.html????????????????????????????Thu, 19 Dec 2019 04:34:00 GMThttp://www.598club.com/markqian86/archive/2019/12/19/217038.htmlhttp://www.598club.com/markqian86/comments/217038.htmlhttp://www.598club.com/markqian86/archive/2019/12/19/217038.html#Feedback0http://www.598club.com/markqian86/comments/commentRss/217038.htmlhttp://www.598club.com/markqian86/services/trackbacks/217038.html?????????

?????????????? 2019-12-19 12:34 ???????o
]]>
C++博客-markqian86 http://www.598club.com/markqian86/archive/2019/12/18/217035.html??????????????

targetServer = serverList[hash(key) % serverList.size]

江苏快三开奖结果??'?????key???hash???????????key???hash????????1?3????????a??????????????|?????3?CRC32???MD5,????3?????hash?3????????|????hashcode????????server????????????????????server???????????3??????????????????????????????????????o????????1?????

???????????1?????????????server?????????????????????????????o?|??????????/?????memcached server????????????1???????-????????????key????????-???????????????????????server??????????'?????????cache??????????????-?????????

???consistent hash???
江苏快三开奖结果?????1?o?????????????3????????'??hash????3???o??????key???hash???????????????????????aserver??1?o????hash?????????????????o?hash???????????????a????????????????????????|?0~2^32????????????????hash?????o?hash(key)????????server?????o?-?????key??????????????server????|????????????????????'????????????????hash??????server?????o??????server???

??o?o???1???????????????????????a???????????????????????a??????????o?????????????

?|???????????o?????????-????????5??amemcached server????2????server???hash????????????????-???

?|????????????????a??????cache?????????|?????????x=hash(key)???????????????-????????????x?o?????????????????????????????????aserver?????o??????server????-???cache????|?????????o?2^32?????????????????????????-????????aserver???????|?x??????????o?A~B?1??'??????1??????-???server????1?o??????B????1

??????????????????????????3??????1?o?????????akey????-???????????-?????????????????????????????amemcached server??????

???1???????????1????3???/???server????'???cache??????????-?????????????
???????????????????????aserver F????|???????


?-??????cache??????????-??????????????-??????????????a?-????o?B~F?1??'??????????????C???????o?F???????????????????????????F~C??????cache????????-??????????????????server??????????????????????????????????cache??????????-????-?????????????????1?o???????????1????2?????1???????o???????????-???cache???????

?????????1
?????????????????3??????1?o????????1????1?????????a??o???????server????????????????????????????????????-?????????????????1????????????????????'cache????????????????????????????server??????



?????????????? 2019-12-18 15:42 ???????o
]]>