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

C/C++:³ÌÐòµÄÄÚ´æ·ÖÅ䷽ʽ


2008-07-07 23:32:21
 
1.ÄÚ´æ·ÖÅ䷽ʽ
ÄÚ´æ·ÖÅ䷽ʽÓÐÈýÖÖ£º
[1]´Ó¾²Ì¬´æ´¢ÇøÓò·ÖÅä¡£ÄÚ´æÔÚ³ÌÐò±àÒëµÄʱºò¾ÍÒѾ­·ÖÅäºÃ£¬Õâ¿éÄÚ´æÔÚ³ÌÐòµÄÕû¸öÔËÐÐÆڼ䶼´æÔÚ¡£ÀýÈçÈ«¾Ö±äÁ¿£¬static±äÁ¿¡£
[2]ÔÚÕ»ÉÏ´´½¨¡£ÔÚÖ´Ðк¯Êýʱ£¬º¯ÊýÄÚ¾Ö²¿±äÁ¿µÄ´æ´¢µ¥Ôª¶¼¿ÉÒÔÔÚÕ»ÉÏ´´½¨£¬º¯ÊýÖ´ÐнáÊøʱÕâЩ´æ´¢µ¥Ôª×Ô¶¯±»ÊÍ·Å¡£Õ»ÄÚ´æ·ÖÅäÔËËãÄÚÖÃÓÚ´¦ÀíÆ÷µÄÖ¸ÁÖУ¬Ð§Âʺܸߣ¬µ«ÊÇ·ÖÅäµÄÄÚ´æÈÝÁ¿ÓÐÏÞ¡£
[3]´Ó¶ÑÉÏ·ÖÅ䣬Òà³Æ¶¯Ì¬ÄÚ´æ·ÖÅä¡£³ÌÐòÔÚÔËÐеÄʱºòÓÃmalloc»ònewÉêÇëÈÎÒâ¶àÉÙµÄÄڴ棬³ÌÐòÔ±×Ô¼º¸ºÔðÔÚºÎʱÓÃfree»òdeleteÊÍ·ÅÄÚ´æ¡£¶¯Ì¬ÄÚ´æµÄÉú´æÆÚÓɳÌÐòÔ±¾ö¶¨£¬Ê¹Ó÷dz£Áé»î£¬µ«Èç¹ûÔÚ¶ÑÉÏ·ÖÅäÁ˿ռ䣬¾ÍÓÐÔðÈλØÊÕËü£¬·ñÔòÔËÐеijÌÐò»á³öÏÖÄÚ´æй©£¬Æµ·±µØ·ÖÅäºÍÊͷŲ»Í¬´óСµÄ¶Ñ¿Õ¼ä½«»á²úÉú¶ÑÄÚËé¿é¡£
2.³ÌÐòµÄÄÚ´æ¿Õ¼ä
Ò»¸ö³ÌÐò½«²Ù×÷ϵͳ·ÖÅä¸øÆäÔËÐеÄÄÚ´æ¿é·ÖΪ4¸öÇøÓò£¬ÈçÏÂͼËùʾ¡£
´úÂëÇø(code area)
 
³ÌÐòÄÚ´æ¿Õ¼ä
È«¾ÖÊý¾ÝÇø(data area)
¶ÑÇø(heap area)
Õ»Çø(stack area)
Ò»¸öÓÉC/C++±àÒëµÄ³ÌÐòÕ¼ÓõÄÄÚ´æ·ÖΪÒÔϼ¸¸ö²¿·Ö,
1¡¢Õ»Çø£¨stack£©—   ÓɱàÒëÆ÷×Ô¶¯·ÖÅäÊÍ·Å £¬´æ·ÅΪÔËÐк¯Êý¶ø·ÖÅäµÄ¾Ö²¿±äÁ¿¡¢º¯Êý²ÎÊý¡¢·µ»ØÊý¾Ý¡¢·µ»ØµØÖ·µÈ¡£Æä²Ù×÷·½Ê½ÀàËÆÓÚÊý¾Ý½á¹¹ÖеÄÕ»¡£
2¡¢¶ÑÇø£¨heap£© —   Ò»°ãÓɳÌÐòÔ±·ÖÅäÊÍ·Å£¬ Èô³ÌÐòÔ±²»ÊÍ·Å£¬³ÌÐò½áÊøʱ¿ÉÄÜÓÉOS»ØÊÕ ¡£·ÖÅ䷽ʽÀàËÆÓÚÁ´±í¡£
3¡¢È«¾ÖÇø£¨¾²Ì¬Çø£©£¨static£©—´æ·ÅÈ«¾Ö±äÁ¿¡¢¾²Ì¬Êý¾Ý¡¢³£Á¿¡£³ÌÐò½áÊøºóÓÐϵͳÊÍ·Å
4¡¢ÎÄ×Ö³£Á¿Çø —³£Á¿×Ö·û´®¾ÍÊÇ·ÅÔÚÕâÀïµÄ¡£ ³ÌÐò½áÊøºóÓÉϵͳÊÍ·Å¡£
5¡¢³ÌÐò´úÂëÇø—´æ·Åº¯ÊýÌ壨Àà³ÉÔ±º¯ÊýºÍÈ«¾Öº¯Êý£©µÄ¶þ½øÖÆ´úÂë¡£
ÏÂÃæ¸ø³öÀý×Ó³ÌÐò£¬
int a = 0; //È«¾Ö³õʼ»¯Çø
char *p1; //È«¾Öδ³õʼ»¯Çø
int main() {
int b; //Õ»
char s[] = "abc"; //Õ»
char *p2; //Õ»
char *p3 = "123456"; //123456\0ÔÚ³£Á¿Çø£¬p3ÔÚÕ»ÉÏ¡£
static int c =0;//È«¾Ö£¨¾²Ì¬£©³õʼ»¯Çø
p1 = new char[10];
p2 = new char[20];
//·ÖÅäµÃÀ´µÃºÍ×Ö½ÚµÄÇøÓò¾ÍÔÚ¶ÑÇø¡£
strcpy(p1, "123456"); //123456\0·ÅÔÚ³£Á¿Çø£¬±àÒëÆ÷¿ÉÄܻὫËüÓëp3ËùÖ¸ÏòµÄ"123456"ÓÅ»¯³ÉÒ»¸öµØ·½¡£
}
3£®¶ÑÓëÕ»µÄ±È½Ï
3.1ÉêÇ뷽ʽ
stack: ÓÉϵͳ×Ô¶¯·ÖÅä¡£ ÀýÈ磬ÉùÃ÷ÔÚº¯ÊýÖÐÒ»¸ö¾Ö²¿±äÁ¿ int b; ϵͳ×Ô¶¯ÔÚÕ»ÖÐΪb¿ª±Ù¿Õ¼ä¡£
heap: ÐèÒª³ÌÐòÔ±×Ô¼ºÉêÇ룬²¢Ö¸Ã÷´óС£¬ÔÚCÖÐmallocº¯Êý£¬C+


Ïà¹ØÎĵµ£º

SQLite C/C++½Ó¿Ú½éÉÜ

ÕâƪÎÄÕÂÊÇʹÓÃSQLite C/C++½Ó¿ÚµÄÒ»¸ö¸ÅÒª½éÉܺÍÈëÃÅÖ¸ÄÏ¡£
ÓÉÓÚÔçÆÚµÄSQLiteÖ»Ö§³Ö5¸öC/C++½Ó¿Ú£¬Òò¶ø·Ç³£ÈÝÒ×ѧϰºÍʹÓ㬵«ÊÇËæ×ÅSQLite¹¦ÄܵÄÔöÇ¿£¬ÐµÄC/C++½Ó¿Ú²»¶ÏµÄÔö¼Ó½øÀ´£¬µ½ÏÖÔÚÓг¬¹ý150¸ö²»Í¬µÄAPI½Ó¿Ú¡£ÕâÍùÍùʹ³õѧÕßÍû¶øÈ´²½¡£ÐÒÔ˵ÄÊÇ£¬´ó¶àÊýSQLiteÖеÄC/C++½Ó¿ÚÊÇרÓõģ¬Òò¶øºÜÉÙ±»Ê¹Óõ½¡£¾¡¹ÜÓÐÕâ ......

CÖÐÈçºÎµ÷ÓÃC++º¯Êý

CÖÐÈçºÎµ÷ÓÃC++º¯Êý?
 
Ç°Õó×Ó±»Îʼ°Ò»¸öÔÚCÖÐÈçºÎµ÷ÓÃC++º¯ÊýµÄÎÊÌ⣬µ±Ê±¼òµ¥»Ø´ðÊǽ«º¯ÊýÓÃextern "C"ÉùÃ÷£¬µ±±»Îʼ°ÈçºÎ½«ÀàÄÚ³ÉÔ±º¯ÊýÉùÃ÷ʱ£¬Ò»Ê±ÓïÈû£¬ºóÀ´ÍøÉϲéÁËÏ£¬ÍøÉÏÓÐÒ»·­ÒëC++Ö®¸¸µÄÎÄÕ¿ÉÒÔ×÷Ϊ½â´ð£¬ËìÄÃÀ´Markһϡ£
 
½« C++ º¯ÊýÉùÃ÷Ϊ``extern "C"''£¨ÔÚÄãµÄ C++ ´úÂëÀï×öÕâ¸öÉùÃ÷£©£¬ ......

C/C++ ʵÏÖÎļþ͸Ã÷¼Ó½âÃÜ

Çë¼û´úÂëÏêϸעÊÍ
//  ÐÞ¸´Éæ¼°ºóÊÓÁбíµÄWin2K¼æÈÝÐÔ
//  Fixes Win2K compatibility regarding lookaside lists.
//
#ifndef _WIN2K_COMPAT_SLIST_USAGE // Add content(Ôö¼ÓÄÚÈÝ)
#define _WIN2K_COMPAT_SLIST_USAGE 
#endif
#include "ntifs.h"
#include "ntdddisk.h"
//
// ÔÚ´úÂëÖпªÆ ......

¼òÊöCºÍC++³ÌÐòԱѧϰÀú³Ì

¹þ¹þ£¡ÓÐÐÒÔÚijÍøÕ¾·¢ÏÖÕâƪÎÄÕ£¬¶Á°Õ£¬¾õµÃÂùÓеÀÀí£¬·¢À´´ó¼ÒÒ»Æð¹²ÃãÖ®   
×ÜÊDZ»Í¬Ñ§ÃÇÎʵ½£¬ÈçºÎѧϰCºÍC++²Å²»Ã£È»£¬²Å²»ÊÇÂÒѧ£¬ÏëÁËһϣ¬ÕâÀï¸ø³öÒ»¸ö×ܵĻظ´¡£
¡¡¡¡Ò»¼ÒÖ®ÑÔ£¬»¶Ó­ÅÄש¹þ¡£
¡¡¡¡1¡¢¿ÉÒÔ¿¼ÂÇÏÈѧϰC.
¡¡¡¡´ó¶àÊýʱºò£¬ÎÒÃÇѧϰÓïÑÔµÄÄ¿µÄ£¬²»ÊÇΪÁ˳ÉΪһ¸öÓïÑÔר¼Ò£¬¶øÊÇÏ£Íû ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ