亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? bget.c

?? 一個簡單實(shí)用的內(nèi)存管理程序
?? C
字號:

//**********************************************************************************************
#ifndef BGET_CONFIG

/*#define TestProg    20000*/	      /* Generate built-in test program
					 if defined.  The value specifies
					 how many buffer allocation attempts
					 the test program should make. */

#define SizeQuant   32		      /* Buffer allocation size quantum:
					 all buffers allocated are a
					 multiple of this size.  This
					 MUST be a power of two. */

/*#define BufDump     1	*/	      /* Define this symbol to enable the
					 bpoold() function which dumps the
					 buffers in a buffer pool. */

/*#define BufValid    1	*/	      /* Define this symbol to enable the
					 bpoolv() function for validating
					 a buffer pool. */

/*#define DumpData    1 */		      /* Define this symbol to enable the
					 bufdump() function which allows
					 dumping the contents of an allocated
					 or free buffer. */

#define BufStats    1		      /* Define this symbol to enable the
					 bstats() function which calculates
					 the total free space in the buffer
					 pool, the largest available
					 buffer, and the total space
					 currently allocated. */

/*#define FreeWipe    1	*/	      /* Wipe free buffers to a guaranteed
					 pattern of garbage to trip up
					 miscreants who attempt to use
					 pointers into released buffers. */

#define BestFit     1		      /* Use a best fit algorithm when
					 searching for space for an
					 allocation request.  This uses
					 memory more efficiently, but
					 allocation will be much slower. */
#endif
//**********************************************************************************************
#include <stdio.h>


#ifdef BGET_ASSERTIONS
    extern void BgetAssertFailed(char const*, char const*, int);
    #define BGET_ASSERT(e)      ((e) ? (void)0 : BgetAssertFailed(#e, __FILE__, __LINE__))
    /*
     * The following macro should be used in preference to BGET_ASSERT(false)
     * because:
     * 1) it is Lint clean -- BGET_ASSERT(false) fires Lint warning 506
     * 2) the code more clearly expresses its intent.
     */
    #define SHOULD_NOT_BE_HERE() BgetAssertFailed("Should not be here!", __FILE__, __LINE__)
#else
    #define BGET_ASSERT(ignore) ((void)0)
    #define SHOULD_NOT_BE_HERE() ((void)0)
#endif /* BGET_ASSERTIONS */



#ifdef BufDump			      /* BufDump implies DumpData */
#ifndef DumpData
#define DumpData    1
#endif
#endif

#ifdef DumpData
#include <ctype.h>
#endif

/*  Declare the interface, including the requested buffer size type,
    bufsize.  */

#include "bget.h"

#define MemSize     int 	      /* Type for size arguments to memxxx()
					 functions such as memcmp(). */

/* Queue links */

struct qlinks {
    struct bfhead *flink;	      /* Forward link */
    struct bfhead *blink;	      /* Backward link */
};

/* Header in allocated and free buffers */

struct bhead {
    bufsize prevfree;		      /* Relative link back to previous
					 free buffer in memory or 0 if
					 previous buffer is allocated.	*/
    bufsize bsize;		      /* Buffer size: positive if free,
					 negative if allocated. */
    bufsize dummy1;
    bufsize dummy2;
    bufsize dummy3;
    bufsize dummy4;
    bufsize dummy5;
    bufsize dummy6;
};
#define BH(p)	((struct bhead *) (p))

/*  Header in directly allocated buffers (by acqfcn) */

struct bdhead {
    bufsize tsize;		      /* Total size, including overhead */
    struct bhead bh;		      /* Common header */
};
#define BDH(p)	((struct bdhead *) (p))

/* Header in free buffers */

struct bfhead {
    struct bhead bh;		      /* Common allocated/free header */
    struct qlinks ql;		      /* Links on free list */
};
#define BFH(p)	((struct bfhead *) (p))

static struct bfhead freelist = {     /* List of free buffers */
    {0, 0},
    {&freelist, &freelist}
};


#ifdef BufStats
static bufsize totalloc = 0;	      /* Total space currently allocated */
static long numget = 0, numrel = 0;   /* Number of bget() and brel() calls */
#endif /* BufStats */


/*  Minimum allocation quantum: */

#define QLSize	(sizeof(struct qlinks))
#define SizeQ	((SizeQuant > QLSize) ? SizeQuant : QLSize)

#define V   (void)		      /* To denote unwanted returned values */

/* End sentinel: value placed in bsize field of dummy block delimiting
   end of pool block.  The most negative number which will  fit  in  a
   bufsize, defined in a way that the compiler will accept. */

#ifdef _MSC_VER
#pragma warning(disable: 4146)    // unary minus operator applied to unsigned type, result still unsigned
#endif
#define ESent	((bufsize) (-(((1L << (sizeof(bufsize) * 8 - 2)) - 1) * 2) - 2))


//**********************************************************************************************
/*  BGET  --  Allocate a buffer.  */
//**********************************************************************************************
void *bget(bufsize requested_size)
{
    bufsize size = requested_size;
    struct bfhead *b;

#ifdef BestFit
    struct bfhead *best;
#endif
    void *buf;

    BGET_ASSERT(size > 0);

    if (size < SizeQ) { 	      /* Need at least room for the */
	size = SizeQ;		      /*    queue links.  */
    }

#ifdef SizeQuant
#if SizeQuant > 1
    size = (size + (SizeQuant - 1)) & (~(SizeQuant - 1));
#endif
#endif

    size += sizeof(struct bhead);
//    Print("sizeof(struct bhead) %u\n", sizeof(struct bhead));
//    size += (sizeof(struct bhead)+ (SizeQuant - 1)) & (~(SizeQuant - 1));     /* Add overhead in allocated buffer
//					 to size required. */

	b = freelist.ql.flink;
#ifdef BestFit
	best = &freelist;
#endif


	/* Scan the free list searching for the first buffer big enough
	   to hold the requested size buffer. */

#ifdef BestFit
	while (b != &freelist) {
	    if (b->bh.bsize >= size) {
		if ((best == &freelist) || (b->bh.bsize < best->bh.bsize)) {
		    best = b;
		}
	    }
	    b = b->ql.flink;		  /* Link to next buffer */
	}
	b = best;
#endif /* BestFit */

	while (b != &freelist) {
	    if ((bufsize) b->bh.bsize >= size) {

		/* Buffer  is big enough to satisfy  the request.  Allocate it
		   to the caller.  We must decide whether the buffer is  large
		   enough  to  split  into  the part given to the caller and a
		   free buffer that remains on the free list, or  whether  the
		   entire  buffer  should  be  removed	from the free list and
		   given to the caller in its entirety.   We  only  split  the
		   buffer if enough room remains for a header plus the minimum
		   quantum of allocation. */

		if ((b->bh.bsize - size) > (SizeQ + (sizeof(struct bhead)))) {
		    struct bhead *ba, *bn;

		    ba = BH(((char *) b) + (b->bh.bsize - size));
		    bn = BH(((char *) ba) + size);
		    BGET_ASSERT(bn->prevfree == b->bh.bsize);
		    /* Subtract size from length of free block. */
		    b->bh.bsize -= size;
		    /* Link allocated buffer to the previous free buffer. */
		    ba->prevfree = b->bh.bsize;
		    /* Plug negative size into user buffer. */
		    ba->bsize = -(bufsize) size;
		    /* Mark buffer after this one not preceded by free block. */
		    bn->prevfree = 0;

#ifdef BufStats
		    totalloc += size;
		    numget++;		  /* Increment number of bget() calls */
#endif
		    buf = (void *) ((((char *) ba) + sizeof(struct bhead)));
		    //Print("0x%08X-%u\n", buf, size);
		    return buf;
		} else {
		    struct bhead *ba;

		    ba = BH(((char *) b) + b->bh.bsize);
		    BGET_ASSERT(ba->prevfree == b->bh.bsize);

                    /* The buffer isn't big enough to split.  Give  the  whole
		       shebang to the caller and remove it from the free list. */

		    BGET_ASSERT(b->ql.blink->ql.flink == b);
		    BGET_ASSERT(b->ql.flink->ql.blink == b);
		    b->ql.blink->ql.flink = b->ql.flink;
		    b->ql.flink->ql.blink = b->ql.blink;

#ifdef BufStats
		    totalloc += b->bh.bsize;
		    numget++;		  /* Increment number of bget() calls */
#endif
		    /* Negate size to mark buffer allocated. */
		    b->bh.bsize = -(b->bh.bsize);

		    /* Zero the back pointer in the next buffer in memory
		       to indicate that this buffer is allocated. */
		    ba->prevfree = 0;

		    /* Give user buffer starting at queue links. */
		    buf =  (void *) &(b->ql);
		    //Print("0x%08X-%u\n", buf, size);
		    return buf;
		}
	    }
	    b = b->ql.flink;		  /* Link to next buffer */
	}
    return NULL;
}


//**********************************************************************************************
/*  BREL  --  Release a buffer.  */
//**********************************************************************************************
void brel(void* buf)
{
    struct bfhead *b, *bn;

    b = BFH(((char *) buf) - sizeof(struct bhead));
#ifdef BufStats
    numrel++;			      /* Increment number of brel() calls */
#endif
    BGET_ASSERT(buf != NULL);

#ifdef FreeWipe
    V memset((char *) buf, 0x55, (MemSize)(-(b->bh.bsize) - sizeof(struct bfhead)));
#endif


    /* Buffer size must be negative, indicating that the buffer is
       allocated. */

    if (b->bh.bsize >= 0) {
	bn = NULL;
    }
    BGET_ASSERT(b->bh.bsize < 0);

    /*	Back pointer in next buffer must be zero, indicating the
	same thing: */

    BGET_ASSERT(BH((char *) b - b->bh.bsize)->prevfree == 0);

#ifdef BufStats
    totalloc += b->bh.bsize;
    BGET_ASSERT(totalloc >= 0);
#endif

    /* If the back link is nonzero, the previous buffer is free.  */

    if (b->bh.prevfree != 0) {

	/* The previous buffer is free.  Consolidate this buffer  with	it
	   by  adding  the  length  of	this  buffer  to the previous free
	   buffer.  Note that we subtract the size  in	the  buffer  being
           released,  since  it's  negative to indicate that the buffer is
	   allocated. */

	register bufsize size = b->bh.bsize;

        /* Make the previous buffer the one we're working on. */
	BGET_ASSERT(BH((char *) b - b->bh.prevfree)->bsize == b->bh.prevfree);
	b = BFH(((char *) b) - b->bh.prevfree);
	b->bh.bsize -= size;
    } else {

        /* The previous buffer isn't allocated.  Insert this buffer
	   on the free list as an isolated free block. */

	BGET_ASSERT(freelist.ql.blink->ql.flink == &freelist);
	BGET_ASSERT(freelist.ql.flink->ql.blink == &freelist);
	b->ql.flink = &freelist;
	b->ql.blink = freelist.ql.blink;
	freelist.ql.blink = b;
	b->ql.blink->ql.flink = b;
	b->bh.bsize = -b->bh.bsize;
    }

    /* Now we look at the next buffer in memory, located by advancing from
       the  start  of  this  buffer  by its size, to see if that buffer is
       free.  If it is, we combine  this  buffer  with	the  next  one	in
       memory, dechaining the second buffer from the free list. */

    bn =  BFH(((char *) b) + b->bh.bsize);
    if (bn->bh.bsize > 0) {

	/* The buffer is free.	Remove it from the free list and add
	   its size to that of our buffer. */

	BGET_ASSERT(BH((char *) bn + bn->bh.bsize)->prevfree == bn->bh.bsize);
	BGET_ASSERT(bn->ql.blink->ql.flink == bn);
	BGET_ASSERT(bn->ql.flink->ql.blink == bn);
	bn->ql.blink->ql.flink = bn->ql.flink;
	bn->ql.flink->ql.blink = bn->ql.blink;
	b->bh.bsize += bn->bh.bsize;

	/* Finally,  advance  to   the	buffer	that   follows	the  newly
	   consolidated free block.  We must set its  backpointer  to  the
	   head  of  the  consolidated free block.  We know the next block
	   must be an allocated block because the process of recombination
	   guarantees  that  two  free	blocks will never be contiguous in
	   memory.  */

	bn = BFH(((char *) b) + b->bh.bsize);
    }

    BGET_ASSERT(bn->bh.bsize < 0);

    /* The next buffer is allocated.  Set the backpointer in it  to  point
       to this buffer; the previous free buffer in memory. */

    bn->bh.prevfree = b->bh.bsize;

}

//**********************************************************************************************
/*  BPOOL  --  Add a region of memory to the buffer pool.  */
//**********************************************************************************************
void bpool(void* buf, bufsize len)
{
    struct bfhead *b = BFH(buf);
    struct bhead *bn;

#ifdef SizeQuant
    len &= ~(SizeQuant - 1);
#endif

    /* Since the block is initially occupied by a single free  buffer,
       it  had	better	not  be  (much) larger than the largest buffer
       whose size we can store in bhead.bsize. */

    BGET_ASSERT(len - sizeof(struct bhead) <= -((bufsize) ESent + 1));

    /* Clear  the  backpointer at  the start of the block to indicate that
       there  is  no  free  block  prior  to  this   one.    That   blocks
       recombination when the first block in memory is released. */

    b->bh.prevfree = 0;

    /* Chain the new block to the free list. */

    BGET_ASSERT(freelist.ql.blink->ql.flink == &freelist);
    BGET_ASSERT(freelist.ql.flink->ql.blink == &freelist);
    b->ql.flink = &freelist;
    b->ql.blink = freelist.ql.blink;
    freelist.ql.blink = b;
    b->ql.blink->ql.flink = b;

    /* Create a dummy allocated buffer at the end of the pool.	This dummy
       buffer is seen when a buffer at the end of the pool is released and
       blocks  recombination  of  the last buffer with the dummy buffer at
       the end.  The length in the dummy buffer  is  set  to  the  largest
       negative  number  to  denote  the  end  of  the pool for diagnostic
       routines (this specific value is  not  counted  on  by  the  actual
       allocation and release functions). */

    len -= sizeof(struct bhead);
    b->bh.bsize = (bufsize) len;
#ifdef FreeWipe
    V memset(((char *) b) + sizeof(struct bfhead), 0x55,
	     (MemSize) (len - sizeof(struct bfhead)));
#endif
    bn = BH(((char *) b) + len);
    bn->prevfree = (bufsize) len;
    /* Definition of ESent assumes two's complement! */
    BGET_ASSERT((~0) == -1);
    bn->bsize = ESent;
}


#ifdef BufStats
//**********************************************************************************************
/*  BSTATS  --	Return buffer allocation free space statistics.  */
//**********************************************************************************************
void bstats(bufsize* curalloc, bufsize* totfree, bufsize* maxfree, long *nget, long* nrel)
{
    struct bfhead *b = freelist.ql.flink;

    *nget = numget;
    *nrel = numrel;
    *curalloc = totalloc;
    *totfree = 0;
    *maxfree = -1;
    while (b != &freelist) {
	BGET_ASSERT(b->bh.bsize > 0);
	*totfree += b->bh.bsize;
	if (b->bh.bsize > *maxfree) {
	    *maxfree = b->bh.bsize;
	}
	b = b->ql.flink;	      /* Link to next buffer */
    }
}
#endif /* BufStats */


?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久不见久久见免费视频1| 一区二区三区 在线观看视频| 五月天欧美精品| 欧美亚洲高清一区| 三级不卡在线观看| 日韩视频在线一区二区| 国产一区不卡视频| 国产精品久久久久久福利一牛影视| 福利一区二区在线观看| 最新不卡av在线| 91电影在线观看| 麻豆国产精品一区二区三区 | 亚洲成人免费视| 欧美一级午夜免费电影| 粉嫩高潮美女一区二区三区 | 极品尤物av久久免费看| 欧美国产一区视频在线观看| 色一情一乱一乱一91av| 麻豆精品视频在线观看视频| 国产精品美女视频| 欧美伦理电影网| 国产成人综合精品三级| 亚洲一二三区在线观看| 久久新电视剧免费观看| 91影院在线免费观看| 日韩激情视频在线观看| 国产精品美女一区二区在线观看| 欧美色窝79yyyycom| 国产一区二区三区免费观看| 亚洲精品少妇30p| 欧美电视剧在线看免费| 99国产精品久久| 久久国产乱子精品免费女| 亚洲色大成网站www久久九九| 欧美久久一二区| 99久久久无码国产精品| 久久国产精品99精品国产| 一区二区三区不卡在线观看| 久久综合国产精品| 在线免费观看日本欧美| 成人性生交大片免费| 美女精品一区二区| 夜夜嗨av一区二区三区网页| 国产午夜亚洲精品羞羞网站| 欧美一区二区大片| 欧美在线啊v一区| 粉嫩av亚洲一区二区图片| 视频一区欧美日韩| 亚洲激情在线播放| 亚洲国产精品ⅴa在线观看| 日韩视频中午一区| 欧美疯狂性受xxxxx喷水图片| 99久久er热在这里只有精品66| 精品一区二区综合| 日本三级亚洲精品| 亚洲大片精品永久免费| 亚洲精品国产无套在线观| 欧美激情一区二区在线| 久久人人爽爽爽人久久久| 3d动漫精品啪啪1区2区免费| 色综合网色综合| 99国产精品99久久久久久| 国产美女娇喘av呻吟久久| 麻豆一区二区三| 视频一区二区中文字幕| 亚洲国产精品一区二区久久恐怖片 | 国模一区二区三区白浆| 日韩va欧美va亚洲va久久| 午夜精品爽啪视频| 亚洲综合一区二区三区| **网站欧美大片在线观看| 日本一区二区三级电影在线观看 | 久久国产精品色婷婷| 美女一区二区久久| 蜜桃一区二区三区在线| 蜜臀av性久久久久蜜臀aⅴ | 91片在线免费观看| 91视频在线看| 在线视频国内一区二区| 欧日韩精品视频| 欧美日韩一本到| 69堂国产成人免费视频| 欧美电影影音先锋| 日韩一区二区电影在线| 天堂久久一区二区三区| 91精品国产一区二区三区| 粉嫩av一区二区三区在线播放| 亚洲欧美视频在线观看| 欧美第一区第二区| 久久免费午夜影院| 国产精品五月天| 一区二区三区中文字幕精品精品| 中文字幕一区二区三区蜜月| 亚洲综合在线免费观看| 日韩av中文字幕一区二区| 九九视频精品免费| 成人精品视频网站| 欧美三级视频在线播放| 日韩精品一区二区在线| 中文字幕电影一区| 亚洲图片有声小说| 青青草视频一区| 成人小视频免费观看| 在线观看日韩高清av| 日韩手机在线导航| 国产精品家庭影院| 亚洲成在人线免费| 国产一区欧美二区| 91色porny| 欧美成人激情免费网| 中文字幕国产一区| 午夜不卡av免费| 成人av先锋影音| 欧美一区二区三区四区在线观看| 久久先锋影音av鲁色资源| 亚洲另类在线一区| 久久精品国产亚洲高清剧情介绍| 成人h精品动漫一区二区三区| 欧美日韩久久久一区| 久久蜜桃av一区精品变态类天堂| 亚洲女人****多毛耸耸8| 久久99精品国产麻豆不卡| 99久久久久久| xfplay精品久久| 亚洲午夜av在线| www.欧美.com| 久久免费国产精品| 丝袜美腿亚洲综合| 99精品国产99久久久久久白柏| 欧美日韩成人一区| 国产精品青草久久| 另类小说一区二区三区| 色综合天天天天做夜夜夜夜做| 26uuu久久综合| 天天av天天翘天天综合网色鬼国产 | 国产资源在线一区| 欧美日韩www| 亚洲免费观看高清| 成人福利在线看| 久久影视一区二区| 午夜精品久久久久久久99水蜜桃| 成人深夜视频在线观看| 久久综合九色综合97_久久久| 天天色图综合网| 欧洲色大大久久| 中文字幕一区二区三区视频| 国产精品正在播放| 精品国产乱码久久久久久免费| 日韩精品一二三四| 欧美日韩国产综合久久 | 91精品中文字幕一区二区三区| ㊣最新国产の精品bt伙计久久| 国产一区二区三区黄视频| 欧美大片在线观看| 日本va欧美va精品发布| 欧美日韩国产综合视频在线观看| 一区二区三区在线观看欧美| 色综合色综合色综合| 自拍av一区二区三区| 不卡欧美aaaaa| 国产精品欧美极品| 成人网在线播放| 国产精品日产欧美久久久久| 成人晚上爱看视频| 国产精品无圣光一区二区| 成人免费不卡视频| 日韩伦理电影网| 色噜噜狠狠色综合中国| 亚洲欧美一区二区不卡| 欧美中文字幕一区| 亚洲成人av免费| 日韩欧美一区电影| 狠狠色狠狠色综合系列| 精品国产凹凸成av人导航| 韩国v欧美v日本v亚洲v| 亚洲国产高清在线| 91视频一区二区| 亚洲第一久久影院| 在线不卡免费av| 精品亚洲免费视频| 国产精品久久久久一区二区三区| 成人午夜激情视频| 亚洲精品一二三| 3d成人h动漫网站入口| 久久激五月天综合精品| 久久午夜电影网| 99精品在线免费| 亚洲妇熟xx妇色黄| 日韩欧美自拍偷拍| 成人美女视频在线观看18| 一区二区三区高清| 日韩免费在线观看| 成人一区二区三区视频在线观看| 亚洲美女精品一区| 欧美撒尿777hd撒尿| 国内精品写真在线观看| **性色生活片久久毛片| 欧美精品欧美精品系列| 国产高清精品久久久久| 亚洲综合在线视频|