c/C++ÄÚ´æ·ÖÅä—new£¬malloc£¬GlobalAllocÏê½â
C++ÄÚ´æ·ÖÅäÃؼ®—new£¬malloc£¬GlobalAllocÏê½â
_______ֻΪÒòÄÚ´æ·ÖÅä¶øÎÞ·¨ÈëÃߵijÌÐòÔ±
Ò»¡£¹ØÓÚÄÚ´æ
¡¡1¡¢ÄÚ´æ·ÖÅ䷽ʽ
¡¡¡¡ÄÚ´æ·ÖÅ䷽ʽÓÐÈýÖÖ£º
¡¡¡¡£¨1£©´Ó¾²Ì¬´æ´¢ÇøÓò·ÖÅä¡£ÄÚ´æÔÚ³ÌÐò±àÒëµÄʱºò¾ÍÒѾ·ÖÅäºÃ£¬Õâ¿éÄÚ´æÔÚ³ÌÐòµÄÕû¸öÔËÐÐÆڼ䶼´æÔÚ
¡£ÀýÈçÈ«¾Ö±äÁ¿£¬static±äÁ¿¡£
¡¡¡¡£¨2£©ÔÚÕ»ÉÏ´´½¨¡£ÔÚÖ´Ðк¯Êýʱ£¬º¯ÊýÄÚ¾Ö²¿±äÁ¿µÄ´æ´¢µ¥Ôª¶¼¿ÉÒÔÔÚÕ»ÉÏ´´½¨£¬º¯ÊýÖ´ÐнáÊøʱÕâЩ´æ
´¢µ¥Ôª×Ô¶¯±»ÊÍ·Å¡£Õ»ÄÚ´æ·ÖÅäÔËËãÄÚÖÃÓÚ´¦ÀíÆ÷µÄÖ¸ÁÖУ¬Ð§Âʺܸߣ¬µ«ÊÇ·ÖÅäµÄÄÚ´æÈÝÁ¿ÓÐÏÞ¡£
¡¡¡¡£¨3£© ´Ó¶ÑÉÏ·ÖÅ䣬Òà³Æ¶¯Ì¬ÄÚ´æ·ÖÅä¡£³ÌÐòÔÚÔËÐеÄʱºòÓÃmalloc»ònewÉêÇëÈÎÒâ¶àÉÙµÄÄڴ棬³ÌÐòÔ±×Ô
¼º¸ºÔðÔÚºÎʱÓÃfree»òdeleteÊÍ·ÅÄÚ´æ¡£¶¯Ì¬ÄÚ´æµÄÉú´æÆÚÓÉÎÒÃǾö¶¨£¬Ê¹Ó÷dz£Áé»î£¬µ«ÎÊÌâÒ²×î¶à¡£
2.ÄÚ´æʹÓôíÎó
¡¡·¢ÉúÄÚ´æ´íÎóÊǼþ·Ç³£Âé·³µÄÊÂÇé¡£±àÒëÆ÷²»ÄÜ×Ô¶¯·¢ÏÖÕâЩ´íÎó£¬Í¨³£ÊÇÔÚ³ÌÐòÔËÐÐʱ²ÅÄܲ¶×½µ½¡£
¶øÕâЩ´íÎó´ó¶àûÓÐÃ÷ÏÔµÄÖ¢×´£¬Ê±ÒþʱÏÖ£¬Ôö¼ÓÁ˸ĴíµÄÄѶȡ£ÓÐʱÓû§ÅÆø³å³åµØ°ÑÄãÕÒÀ´£¬³ÌÐòȴûÓÐ
·¢ÉúÈκÎÎÊÌ⣬ÄãÒ»×ߣ¬´íÎóÓÖ·¢×÷ÁË¡£ ³£¼ûµÄÄÚ´æ´íÎó¼°Æä¶Ô²ßÈçÏ£º
* ÄÚ´æ·ÖÅäδ³É¹¦£¬È´Ê¹ÓÃÁËËü¡£
¡¡¡¡±à³ÌÐÂÊÖ³£·¸ÕâÖÖ´íÎó£¬ÒòΪËûÃÇûÓÐÒâʶµ½ÄÚ´æ·ÖÅä»á²»³É¹¦¡£³£Óýâ¾ö°ì·¨ÊÇ£¬ÔÚʹÓÃÄÚ´æ֮ǰ¼ì²é
Ö¸ÕëÊÇ·ñΪNULL¡£Èç¹ûÊÇÓÃmalloc»ònewÀ´ÉêÇëÄڴ棬Ӧ¸ÃÓÃif(p==NULL) »òif(p!=NULL)½øÐзÀ´í´¦Àí¡£
¡¡¡¡* ÄÚ´æ·ÖÅäËäÈ»³É¹¦£¬µ«ÊÇÉÐδ³õʼ»¯¾ÍÒýÓÃËü¡£
¡¡¡¡·¸ÕâÖÖ´íÎóÖ÷ÒªÓÐÁ½¸öÆðÒò£ºÒ»ÊÇûÓгõʼ»¯µÄ¹ÛÄ¶þÊÇÎóÒÔΪÄÚ´æµÄȱʡ³õֵȫΪÁ㣬µ¼ÖÂÒýÓóõÖµ
´íÎó£¨ÀýÈçÊý×飩¡£ ÄÚ´æµÄȱʡ³õÖµ¾¿¾¹ÊÇʲô²¢Ã»ÓÐͳһµÄ±ê×¼£¬¾¡¹ÜÓÐЩʱºòΪÁãÖµ£¬ÎÒÃÇÄþ¿ÉÐÅÆäÎÞ²»
¿ÉÐÅÆäÓС£ËùÒÔÎÞÂÛÓúÎÖÖ·½Ê½´´½¨Êý×飬¶¼±ðÍüÁ˸³³õÖµ£¬¼´±ãÊǸ
Ïà¹ØÎĵµ£º
VB
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
MSComm1.CommPort = i1
MSComm1.PortOpen = True
MSComm1.InputMode = comInputModeBinary
MSComm1.InBufferCount = 0
& ......
CÖÐÈçºÎµ÷ÓÃC++º¯Êý?
Ç°Õó×Ó±»Îʼ°Ò»¸öÔÚCÖÐÈçºÎµ÷ÓÃC++º¯ÊýµÄÎÊÌ⣬µ±Ê±¼òµ¥»Ø´ðÊǽ«º¯ÊýÓÃextern "C"ÉùÃ÷£¬µ±±»Îʼ°ÈçºÎ½«ÀàÄÚ³ÉÔ±º¯ÊýÉùÃ÷ʱ£¬Ò»Ê±ÓïÈû£¬ºóÀ´ÍøÉϲéÁËÏ£¬ÍøÉÏÓÐÒ»·ÒëC++Ö®¸¸µÄÎÄÕ¿ÉÒÔ×÷Ϊ½â´ð£¬ËìÄÃÀ´Markһϡ£
½« C++ º¯ÊýÉùÃ÷Ϊ``extern "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"
//
// ÔÚ´úÂëÖпªÆ ......
º¯Êýµ÷ÓÃÕ»µÄʵÏÖ¡£¿ÉÓÃÓÚʵÏÖ¼òµ¥µÄ½Å±¾½âÊÍÆ÷¡£
ÉùÃ÷:
#pragma once
const int BUFFERSIZE = 1024;
const int growfactor = 2;
// this stack is used as call stack.
class TStack{
private:
size_t size; // the stack length
size_t pos; // the stack top position
cha ......