C++博客-markqian86 http://www.598club.com/markqian86/practice makes perfect???????????????????????1?????????????zh-cnThu, 20 Feb 2020 04:04:44 GMTThu, 20 Feb 2020 04:04:44 GMT60C++博客-markqian86 http://www.598club.com/markqian86/archive/2020/02/16/217131.html????????????????????????????Sun, 16 Feb 2020 11:51:00 GMThttp://www.598club.com/markqian86/archive/2020/02/16/217131.htmlhttp://www.598club.com/markqian86/comments/217131.htmlhttp://www.598club.com/markqian86/archive/2020/02/16/217131.html#Feedback0http://www.598club.com/markqian86/comments/commentRss/217131.htmlhttp://www.598club.com/markqian86/services/trackbacks/217131.html1. ??????????VBoxAdditions????????????http://download.virtualbox.org/virtualbox/5.1.12/Oracle_VM_VirtualBox_Extension_Pack-5.1.12.vbox-extpack
2. ?????????????????????????????????????????-????????o??????????????
3. ??????????VBoxAdditions????????????http://download.virtualbox.org/virtualbox/5.1.12/VBoxGuestAdditions_5.1.12.iso
4. CentOS?????????????
mkdir /mnt/cdrom
mount /dev/cdrom /mnt/cdrom
5. ???????????????????1???????????????-???????|??????'???????????-????????????????????o?????????????'????3????????????
cp -R /mnt/cdrom /usr/local/src/VBoxAdditions
6. ?????????????????????|?????????????????????|?????2???????????1???????-???????3?????
yum install gcc
yum install make
yum install kernel-headers
yum install kernel-devel
7. ????????????1????????????????./VBoxLinuxAdditions.run install

??????3????!!!!!!!!!!!!!!!!!

8. ????????o????????1???
mkdir /mnt/share
mount -t vboxsf vmshare /mnt/share
?3?????vmshare??ovisualbox???????????????????????o??????????????????
ln -s /mnt/share /home/myshare (?????????????myshare???)

9. ?????????
————————————————
??????????????????????oCSDN?????????????????????????????????????????a CC 4.0 BY-SA ????????????????????????????????o?????????????????????
??????????????http://blog.csdn.net/suma110/article/details/54343686


?????????????? 2020-02-16 19:51 ???????o
]]>
C++博客-markqian86 http://www.598club.com/markqian86/archive/2020/02/15/217127.html????????????????????????????Sat, 15 Feb 2020 03:45:00 GMThttp://www.598club.com/markqian86/archive/2020/02/15/217127.htmlhttp://www.598club.com/markqian86/comments/217127.htmlhttp://www.598club.com/markqian86/archive/2020/02/15/217127.html#Feedback0http://www.598club.com/markqian86/comments/commentRss/217127.htmlhttp://www.598club.com/markqian86/services/trackbacks/217127.htmlMariaDB ??????o????????3??????? MySQL ????????a????????????|???????o?????o????'????????? GPL ????????????????????????a????????????????1????????????2a????????????'-?o? MySQL ??????????? MySQL ?-?o????????????????????-????o???????????????1???????????????a???????MariaDB??????????1mysql??????????1?3??1????????????

??????centos7?2????????????o?Mariadb????????????????a????????2?????????????2????????????????????????????2?????????o??????????????????1?????????????o?????????????????? yum remove mariadb-server

 ???????3??????????

 

1????????MariaDB

 ????yum?????????o???????????????????????mariadb-server????????????????mariadb????????a????????????????????a??????????????

[root@mini ~]# yum install mariadb-server

 

2????????MariaDB

1?????????????????|????|????MariaDB????????????????1????????o?????o?????

[root@mini ~]# systemctl start mariadb  # ???????????? [root@mini ~]# systemctl enable mariadb  # ???????o?????o?a???????????

2???|???????????|???????????o??????????????????????mysql????????

[root@mini ~]# mysql_secure_installation

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

???????????
Enter current password for root (enter for none):  # ???????????o????o?????????root?????????(?3??????????3????root?????????)????????????????????2????????????????????'???????|  Set root password? [Y/n]  # ??????????????y  New password:  # ???????? Re-enter new password:  # ?????????????????  Remove anonymous users? [Y/n]  # ???????????????? y  Disallow root login remotely? [Y/n]  # ??????root?????????????n?????????y/n??????????????root??????????  Remove test database and access to it? [Y/n]  # ????test??????o????y??????????n???????????????????o???-???????????atest??????o??????????????|?  Reload privilege tables now? [Y/n]  # ??????????????????y????????????????????1???
???????????

4?????????????|?????????????????????o??  MariaDB [(none)]> ???o?2????????-???????????????MariaDB??????o??o?

???????????
[root@mini ~]# mysql -u root -p Enter password: Welcome to the MariaDB monitor.  Commands end with ; or \g. Your MariaDB connection id is 8 Server version: 5.5.60-MariaDB MariaDB Server  Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.  Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  MariaDB [(none)]>
???????????

 

3????????MariaDB?-???|????outf-8

 1???/etc/my.cnf ??????

??  [mysqld]  ????-?????????

init_connect='SET collation_connection = utf8_unicode_ci' init_connect='SET NAMES utf8' character-set-server=utf8 collation-server=utf8_unicode_ci skip-character-set-client-handshake

2???/etc/my.cnf.d/client.cnf ??????

??  [client]  ????-?????????

default-character-set=utf8

3???/etc/my.cnf.d/mysql-clients.cnf  ??????

??  [mysql]  ????-?????????

default-character-set=utf8

4??????????????

[root@mini ~]# systemctl restart mariadb

5????????mariadb???????-???|??

 ??a??????-???|?????
 ??????-???|?????

 

4????????????mariadb??????o?

mariadb???????????? root ???????????????????????????? navicat ????????????????o?

1?????3?-?2??????

① ??3?-?2?????? systemctl stop firewalld 

[root@mini ~]# systemctl stop firewalld

② ???????3?-?2????????????????????????????????????????????????????-?a?|?????????????3306???????????????2??????

???????????
[root@mini ~]# firewall-cmd --query-port=3306/tcp  # ??????3306???????????|?????? no [root@mini ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent  # ??????3306?????? success [root@mini ~]# firewall-cmd --reload  # ??????2?????? success [root@mini ~]# firewall-cmd --query-port=3306/tcp  # ??????3306???????????|?????? yes
???????????

2????????????mysql??????o???-???user?

???????????
[root@mini ~]# mysql -u root -p  # ????????????????????????????o?  MariaDB [(none)]> use mysql;  MariaDB [mysql]> select host, user from user; +-----------+------+ | host      | user | +-----------+------+ | 127.0.0.1 | root | | ::1       | root | | mini      | root | +-----------+------+ 3 rows in set (0.00 sec)
???????????

3?????????????o???????-?????-??????1??o "%" ??????????????o?????omini???

???????????
MariaDB [mysql]> update user set host='%' where host='mini'; Query OK, 1 row affected (0.00 sec) Rows matched: 1  Changed: 1  Warnings: 0  MariaDB [mysql]> select host, user from user; +-----------+------+ | host      | user | +-----------+------+ | %         | root | | 127.0.0.1 | root | | localhost | root | +-----------+------+ 3 rows in set (0.00 sec)
???????????

4????????????????????????mariadb????????????????o????????3???

MariaDB [mysql]> flush privileges; Query OK, 0 rows affected (0.00 sec)
[root@mini ~]# systemctl restart mariadb

?3???????????????????????????o???-???????????????????????????????-

 

6????????????????mariadb

 



?????????????? 2020-02-15 11:45 ???????o
]]>
C++博客-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      offset???????????????????1????2?-??????????????-???????????'??????o????????????????????????????????MAGIC NUMBER a???????2?-??????????????'???

2????????????????????linux?????????????????????, ??????o|???p43
      ??o|????????????'?'|????????????????' +=??????(????????????????'); while {run get_task( min(?????????????') ) ;}(true);
     ?????????????????????????????????????????????3???????????a????????????-??????????????????????????????????????? ?|??-?????????'=???????????/???o| ????????????

3????-???????????????linux?????????????????????, ??????o|???p50
   ???????????a???????2?????o?????????o|?-?????????|???????????

epoll?o????????a?????+???a????????mutex+?o???????????
??????3?????????????????????->?????+rpc->??????????????? ???????'???????????????o?????-?1s??????????????a???????????????????????????o???????????o???????????????????
ECS????????word=system+entity; system=sys1+sys2+sysn; entity=componentN;
???????????????????????int info_flg; T vct_info; ???linux?????????????????????, ????-??-???p111??? tasklet?????????????????-??-??????????o|?-???????????????????o??????ksoftirqd????????acpu?????????????o???????o????????????????1????????-??-????2?-???????????o??????????

?????????????? 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
]]>