GNU C library ±Ê¼Ç£¨2£©
ÄÚÈÝ£ºMemory
1. ¼¸¸ö»ù±¾¸ÅÄpage¡¢frame¡¢paging¡¢segment¡£
½ø³Ì·ÖÅäÄÚ´æµÄÁ½ÖÖģʽ£¬Ò»¸öʹÓà exec ϵÁк¯Êý£¬Ò»¸öʹÓà programmatically£¨malloc µÈº¯Êý£©¡£
ÖØÒªµÄ segment ÓÐ text segment£¨´æ·Å´úÂëµÈµÈ£¬Ò»°ãÔÚ½ø³ÌµÄÉúÃüÖÜÆÚÖв»±ä£©¡¢data segment
£¨´æ·ÅÊý¾Ý£¬ÄÜÓÃһЩº¯ÊýÀ´µ÷Õû´óС£¬²»¹ýµÍλ¶ËλÖò»±ä£©¡¢stack segment£¨Ëæ×ÅʹÓõĶÑÕ»
±ä´ó¶ø±ä´ó£¬µ«²»±äС...£©
2. ÄÚ´æµÄ¾²Ì¬·ÖÅäºÍ×Ô¶¯·ÖÅ䡣ǰÕßÊǶÔÓÚ static ±äÁ¿»òÈ«¾Ö±äÁ¿£¬Ò»µ©¿ªÊ¼¾Í·ÖÅ䣬¼´Ò»Ö±´æÔÚµ½×îºó¡£
ºóÕßÊÇÁÙʱ±äÁ¿£¬Èçµ÷Óú¯Êý¡£ÖµµÃ×¢ÒâµÄÊÇ£º
In GNU C, the size of the automatic storage can be an expression that
varies. In other C implementations, it must be a constant.
3. ÄÚ´æµÄ¶¯Ì¬·ÖÅ䲻Ϊ C ÓïÑÔ±¾ÉíÖ§³Ö£¬²»Ïñ C++¡£»ù±¾·½·¨ÊÇ
void * malloc (size_t size)
·ÖÅäµ½µÄÄÚ´æûÓгõʼ»¯£¨calloc »á×öÇåÁ㣬clear allocate£©£¬Òò´ËÄÜÓà memset À´
½øÐгõʼ»¯¡£·ÖÅäºóÓ¦¼ì²â·µ»ØÖ¸ÕëÊÇ·ñΪ NULL¡£malloc ·µ»ØµÄÒ»¸ö¿é¶àÊýÇé¿ö϶ÔÆë
£¨ÕâÑùÄÜ´æ´¢ÈÎÒâÀàÐ͵ÄÊý¾Ý£©¹ýÁË£¬µØַΪ 8 µÄ±¶Êý£¨64 λϵͳÀïÃæÊÇ 16 µÄ±¶Êý£©£¬
ÔÚһЩÌرðÇé¿öÏ£¨page µÄ±ß½ç£©ÄÜÀûÓà memalign¡¢posix_memalign¡¢vlign À´·µ»Ø
¶ÔÆ루2 µÄÃݴΣ©µÄÄÚ´æ¿é¡£free µÄÄÚ´æ·Ç³£ÉÙ±»·µ»¹¸ø²Ù×÷ϵͳ£¬¶àÊýÇé¿ö±»Áô×÷ºóÃæ
malloc ʹÓá£Èç¹ûÐèÒªµ÷ÕûÒÑ malloc µÄ¿éµÄ´óС£¬Ê¹Óà realloc¡£glibc ²»»á½«·ÖÅäµÄ¿é
¶Ô 2 µÄÃݴνøÐÐÏòÉÏÈ¡Õû¡£
4. Ò»´ÎÐÔ·ÖÅä·Ç³£´óµÄÄڴ棨´óÓÚÒ»¸ö page£©»áʹÓÃÏò 2 µÄÃÝ´ÎÈ¡ÕûµÄ²ßÂÔ£¬Ê¹Óà mmap
Ïà¹ØµÄº¯Êý mallopt£¬ÕâÖÖ·ÖÅäµÃµ½µÄÄÚ´æÔÚ free ʱ»á·µ»Ø¸ø²Ù×÷ϵͳ¡£
5. Ôõôµ÷Õû malloc µÄÐÐΪ£¿Ê¹Óà mallopt µ÷ÕûһЩ²ÎÊýµÄÖµ£¨malloc.h£©£¬Èç
M_TRIM_THRESHOLD£¨·µ»Ø¸ø OS µÄÄÚ´æµÄÒ»¸öãÐÖµ£©¡¢M_MMAP_THRESHOLD
£¨´óÓÚ´ËÖµµÄÄÚ´æ·ÖÅäÇëÇóʹÓà mmap ϵͳµ÷Ó㩵ȵȡ£
6. ·ÖÅäµÄÄÚ´æÀ´×Զѣ¨heap£©£¬ÄÜÓÃ
int mcheck (void (*abortfn) (enum mcheck_status status))
À´¼ì²é·ÖÅäÄÚ´æµÄÒ»ÖÂÐÔ£¬µ÷ÓÃÔÚ malloc ֮ǰ¡£
enum mcheck_status mprobe (void *pointer)
ΪÌض¨µÄÒ»¿éÄÚ´æ×ö¼ì²é¡£ÕⶼÊÇ GNU extension¡££¨mcheck.h£©
7. ΪÁË·½±ãµ÷ÊÔ£¬glibc ΪÓû§ÌṩÁË malloc µÈµÈº¯ÊýµÄ¹³×Ó£¨hook£©£¬Èç __malloc_hook
¶ÔÓ¦µÄÊǸöº¯ÊýÖ¸Õ룬
void *function (size_t size, const void *caller)
ÆäÖÐ caller Êǵ÷Óà ma
Ïà¹ØÎĵµ£º
´ÓÁ½µÀ¾µäÊÔÌâ̸C/C++ÖÐÁªºÏÌ壨union£©µÄʹÓÃ
ÊÔÌâÒ»£º±àдһ¶Î³ÌÐòÅжÏϵͳÖеÄCPUÊÇLittle endian»¹ÊÇBig endianģʽ£¿
·ÖÎö£º
×÷Ϊһ¸ö¼ÆËã»úÏà¹ØרҵµÄÈË£¬ÎÒÃÇÓ¦¸ÃÔÚ¼ÆËã»ú×é³ÉÖж¼Ñ§Ï°¹ýʲô½ÐLittle endianºÍBig endian¡£Little endianºÍBig endianÊÇCPU´æ·ÅÊý¾ÝµÄÁ½ÖÖ²»Í¬Ë³Ðò¡£¶ÔÓÚÕûÐÍ¡¢³¤ÕûÐ͵ÈÊý¾ÝÀàÐÍ£ ......
±¾ÎĵÄд×÷Ä¿µÄ²¢²»ÔÚÓÚÌṩC/C++³ÌÐòÔ±ÇóÖ°ÃæÊÔÖ¸µ¼£¬¶øÖ¼ÔÚ´Ó¼¼ÊõÉÏ·ÖÎöÃæÊÔÌâµÄÄÚº¡£ÎÄÖеĴó¶àÊýÃæÊÔÌâÀ´×Ô¸÷´óÂÛ̳£¬²¿·ÖÊÔÌâ½â´ðÒ²²Î¿¼ÁËÍøÓѵÄÒâ¼û¡£
¡¡¡¡Ðí¶àÃæÊÔÌâ¿´ËƼòµ¥£¬È´ÐèÒªÉîºñµÄ»ù±¾¹¦²ÅÄܸø³öÍêÃÀµÄ½â´ð¡£ÆóÒµÒªÇóÃæÊÔÕßдһ¸ö×î¼òµ¥µÄstrcpyº¯Êý¶¼¿É¿´³öÃæÊÔÕßÔÚ¼¼ÊõÉϾ¿¾¹´ïµ½ÁËÔõÑùµÄ³Ì¶È£¬Î ......
Ô¤´¦ÀíÆ÷£¨Preprocessor£©
1. ÓÃÔ¤´¦ÀíÖ¸Áî#define ÉùÃ÷Ò»¸ö³£Êý£¬ÓÃÒÔ±íÃ÷1ÄêÖÐÓжàÉÙÃ루ºöÂÔÈòÄêÎÊÌ⣩
#define SECONDS_PER_YEAR (60 * 60 * 24 * 365)UL
ÎÒÔÚÕâÏë¿´µ½¼¸¼þÊÂÇ飺
1). #define Óï·¨µÄ»ù±¾ÖªÊ¶£¨ÀýÈ磺²»ÄÜÒԷֺŽáÊø£¬À¨ºÅµÄʹÓ㬵ȵȣ©
2). ¶®µÃÔ¤´¦ÀíÆ÷½«ÎªÄã¼ÆËã³£Êý±í´ïʽµÄÖµ£¬Òò´Ë£¬Ö±½Ó ......
ͻ񻣼
±¾ÎÄ´Ó½éÉÜ»ù´¡¸ÅÄîÈëÊÖ£¬Ì½ÌÖÁËÔÚC/C++ÖжÔÈÕÆÚºÍʱ¼ä²Ù×÷ËùÓõ½µÄÊý¾Ý½á¹¹ºÍº¯Êý£¬²¢¶Ô¼Æʱ¡¢Ê±¼äµÄ»ñÈ¡¡¢Ê±¼äµÄ¼ÆËãºÍÏÔʾ¸ñʽµÈ·½Ãæ½øÐÐÁ˲ûÊö¡£±¾ÎÄ»¹Í¨¹ý´óÁ¿µÄʵÀýÏòÄãչʾÁËtime.hÍ·ÎļþÖÐÉùÃ÷µÄ¸÷ÖÖº¯ÊýºÍÊý¾Ý½á¹¹µÄÏêϸʹÓ÷½·¨¡£
¹Ø¼ü×Ö£ºUTC£¨ÊÀ½ç±ê׼ʱ¼ä£©£¬Calendar Time£¨ÈÕÀúʱ¼ä£©£¬epoch ......