Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

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++Êý×éÃûÓëÖ¸ÕëÇø±ð

 ÒÔÏÂÎÄÕÂתÔØÓÚ:ΪÁËѧϰºÍÊÕ²Ø
http://tech.163.com/school · 2005-08-23 11:05:18 · À´Ô´: Ì켫Íø
C/C++Êý×éÃûÓëÖ¸ÕëÇø±ð
¡¡¡¡ÒýÑÔ
¡¡¡¡Ö¸ÕëÊÇC/C++ÓïÑÔµÄÌØÉ«£¬¶øÊý×éÃûÓëÖ¸ÕëÓÐÌ«¶àµÄÏàËÆ£¬ÉõÖÁºÜ¶àʱºò£¬Êý×éÃû¿ÉÒÔ×÷ΪָÕëʹÓá£ÓÚÊǺõ£¬ºÜ¶à³ÌÐòÉè¼ÆÕ߾ͱ»¸ãºýÍ¿ÁË¡£¶øÐí¶àµÄ´óѧÀÏʦ£¬ËûÃÇ ......

CÖкê#ºÍ##µÄÔËÓÃ

 #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#define f(a,b) a##b
#define g(a)  #a
#define h(a) g(a)
int main()   
{   
    char a = 'a';      
    ......

CÌâÄ¿3

1. ÓÃÔ¤´¦ÀíÖ¸Áî#define ÉùÃ÷Ò»¸ö³£Êý£¬ÓÃÒÔ±íÃ÷1ÄêÖÐÓжàÉÙÃ루ºöÂÔÈòÄêÎÊÌ⣩
#define SECONDS_PER_YEAR   (60 * 60 * 24 * 365)UL
ÎÒÔÚÕâÏë¿´µ½¼¸¼þÊÂÇ飺
     1). #define Óï·¨µÄ»ù±¾ÖªÊ¶£¨ÀýÈ磺²»ÄÜÒԷֺŽáÊø£¬À¨ºÅµÄʹÓ㬵ȵȣ©
     2). ¶®µÃÔ¤´¦ÀíÆ÷½«Î ......

CÓïÑÔÁ¬½ÓmysqlÊý¾Ý¿â£¬¶ÁÈ¡mysqlÄÚÈÝ

 //linuxϱàÒëg++ $(mysql_config --cflags)  ***.cpp  $(mysql_config --libs)
/*mysqlÊý¾Ý¿âÖбíµÄÄÚÈÝ
mysql> select * from maindb;
+------------------+---------+-------------+---------+----------+---------------------+---------------------+---------------------+------------------- ......

curl c api

 curl c api
¹ØÓÚCurlµÄ½éÉܺܶ࣬ÕâÀï²»Ïêϸ½éÉÜ£¬Ö÷Ҫ̸һϼòµ¥Ó¦Óá£
×î½üÑо¿ÁËÒ»ÏÂLinuxϵÄcurl C API,curl c APIµÄÎĵµ±È½Ï·á¸»£¬Î¨Ò»¾ÍÊDzéÕÒÆðÀ´£¬·ÑЩʱ¼ä¡£CurlµÄC APIºÍcurlµÄPHP API£¬º¯Êý½Ó¿ÚºÍ×÷ÓôóÖÂÏàͬ£¬ËùÒÔÈç¹ûÓÐPHP APIʹÓþ­ÑéÓ¦¸ÃºÜºÃÀí½â¡£
1£ºCURLcode curl_global_init(long flags);º¯ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ