C/C++????洢??????
???????????? ???????[ 2014/4/30 10:36:07 ] ????????mmap C++
????1. mmap??munmap
#include <sys/mman.h>
void *mmap(void *start??size_t length?? int prot?? int flags??int fd?? off_t offset);
int munmap(void *start??size_t length);
????mmap??????????????????????????檔????????????????????????С????????????С???????????????????佫??????mmap()????????y??????????????????????????????檔??????????????????????????????????????????????????з?????????????read()??write???????????
????munmap???????????start???????????????????????length???????????????С?????????????????exec??????????????????????????????????????????????????????????????????????????????????????0?????????1????????????errno?д??????EINVAL
????2. malloc??free
??????????????????mmap??munmap??????????????????????????????????C?????????????????洢????????(dynamic memory allocator)????????и??????????
???????????????????????????????????洢????????????heap???????????????????鯔???С??饗block??????????????????????????????????洢?????chunk???????????????????????е??
?????????????????????????????????????????飬??????????????????????????????????????顣???????????explicit alloctor???????????????????κ???????顣???????????implicit allocator????????????????????garbage collector?????????????????????????????????????????????????顣
????malloc???????????磬?????????洢?????????????洢??????????????????NULL????????errno??malloc??????????????洢?????????????????????洢??????ó?????????calloc??calloc?????????malloc?????????????????????洢?????????????????????????????С?????????realloc??????
????????洢??????????????malloc????????????mmap??munmap???????????????????洢????????????????sbrk??????sbrk?????????brk??????heap??????????????????sbrk????brk????????????-1??????errno?????ENOMEM??
????Free??????????????顣??C????????????У???????malloc?????????Free???????????????????飬??????????free??????Щ??????????????С?
????3. ????????????????
????????????????洢???????????????(reachability graph)????н????????????????????????????????е?????????顣?????p->q??ζ???p?е????λ??????q???λ?á??????????????????????е?λ????????????????????Щλ??????????????????????????????洢???ж?д????????????????????????????????????????????????????????????????????????????????????????????????
??????ML??Java?????????????????????????????δ????????????к??????????????????????????????????????????????е????????????????C??C++???????????????????????????????????????????????????????????????????????conservative garbage collector?????????????????????????????????????????????????????????Щ????????????????????????
????????????????????????????????????malloc?????malloc???????????????п飬?????????????????????????????Щ???????????????С??????????????飬?????????Free?????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11