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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? balloc.c

?? 開發板bios源碼 開發板bios源碼
?? C
?? 第 1 頁 / 共 2 頁
字號:
/*
 * balloc.c -- Block allocation module
 *
 * Copyright (c) GoAhead Software Inc., 1995-2000. All Rights Reserved.
 *
 * See the file "license.txt" for usage and redistribution license requirements
 *
 * $Id: balloc.c,v 1.2 2001/12/06 16:28:24 bporter Exp $
 */

/******************************** Description *********************************/

/*
 *	This module implements a very fast block allocation scheme suitable for
 *	ROMed environments. It maintains block class queues for rapid allocation
 *	and minimal fragmentation. This module does not coalesce blocks. The 
 *	storage space may be populated statically or via the traditional malloc 
 *	mechanisms. Large blocks greater than the maximum class size may be 
 *	allocated from the O/S or run-time system via malloc. To permit the use 
 *	of malloc, call bopen with flags set to B_USE_MALLOC (this is the default).
 *	It is recommended that bopen be called first thing in the application. 
 *	If it is not, it will be called with default values on the first call to 
 *	balloc(). Note that this code is not designed for multi-threading purposes
 *	and it depends on newly declared variables being initialized to zero.
 */  

/********************************* Includes ***********************************/

#define IN_BALLOC

#ifdef UEMF
	#include	"uemf.h"
#else
	#include	"basic/basicInternal.h"
#endif

#include	<stdarg.h>
#include	<stdlib.h>

#ifndef NO_BALLOC
/********************************* Defines ************************************/

/*
 *	Define B_STATS if you wish to track memory block and stack usage
 */
#ifdef B_STATS
/*
 *	Optional statistics
 */

typedef struct {
	long	alloc;								/* Block allocation calls */
	long	inuse;								/* Blocks in use */
} bStatsType;

typedef struct {
	char_t 	file[FNAMESIZE];
	long	allocated;							/* Bytes currently allocated */
	long	count;								/* Current block count */
	long	times;								/* Count of alloc attempts */
	long	largest;							/* largest allocated here */
	int		q;
} bStatsFileType;

/*
 *	This one is very expensive but great stats
 */
typedef struct {
	void			*ptr;						/* Pointer to memory */
	bStatsFileType	*who;						/* Who allocated the memory */
} bStatsBlkType;

static bStatsType		bStats[B_MAX_CLASS];	/* Per class stats */
static bStatsFileType 	bStatsFiles[B_MAX_FILES];/* Per file stats */
static bStatsBlkType 	bStatsBlks[B_MAX_BLOCKS];/* Per block stats */
static int			 	bStatsBlksMax = 0;		/* Max block entry */
static int			 	bStatsFilesMax = 0;		/* Max file entry */
static int 				bStatsMemInUse = 0;		/* Memory currently in use */
static int 				bStatsBallocInUse = 0;	/* Memory currently balloced */
static int 				bStatsMemMax = 0;		/* Max memory ever used */
static int 				bStatsBallocMax = 0;	/* Max memory ever balloced */
static void				*bStackMin = (void*) -1;/* Miniumum stack position */
static void				*bStackStart;			/* Starting stack position */
static int 				bStatsMemMalloc = 0;	/* Malloced memory */
#endif /* B_STATS */

/*
 *	ROUNDUP4(size) returns the next higher integer value of size that is 
 *	divisible by 4, or the value of size if size is divisible by 4.
 *	ROUNDUP4() is used in aligning memory allocations on 4-byte boundaries.
 *
 *	Note:  ROUNDUP4() is only required on some operating systems (IRIX).
 */

#define ROUNDUP4(size) ((size) % 4) ? (size) + (4 - ((size) % 4)) : (size)

/********************************** Locals ************************************/
/*
 *	bQhead blocks are created as the original memory allocation is freed up.
 *	See bfree.
 */
static bType			*bQhead[B_MAX_CLASS];	/* Per class block q head */
static char				*bFreeBuf;				/* Pointer to free memory */
static char				*bFreeNext;				/* Pointer to next free mem */
static int				bFreeSize;				/* Size of free memory */
static int				bFreeLeft;				/* Size of free left for use */
static int				bFlags = B_USE_MALLOC;	/* Default to auto-malloc */
static int				bopenCount = 0;			/* Num tasks using balloc */

/*************************** Forward Declarations *****************************/

#ifdef B_STATS
static void bStatsAlloc(B_ARGS_DEC, void *ptr, int q, int size);
static void bStatsFree(B_ARGS_DEC, void *ptr, int q, int size);
static void bstatsWrite(int handle, char_t *fmt, ...);
static int 	bStatsFileSort(const void *cp1, const void *cp2);
#endif /* B_STATS */

#if (defined (B_FILL) || defined (B_VERIFY_CAUSES_SEVERE_OVERHEAD))
static void bFillBlock(void *buf, int bufsize);
#endif

#ifdef B_VERIFY_CAUSES_SEVERE_OVERHEAD
static void verifyUsedBlock(bType *bp, int q);
static void verifyFreeBlock(bType *bp, int q);
void verifyBallocSpace();
#endif

static int ballocGetSize(int size, int *q);

/********************************** Code **************************************/
/*
 *	Initialize the balloc module. bopen should be called the very first thing
 *	after the application starts and bclose should be called the last thing 
 *	before exiting. If bopen is not called, it will be called on the first 
 *	allocation with default values. "buf" points to memory to use of size 
 *	"bufsize". If buf is NULL, memory is allocated using malloc. flags may 
 *	be set to B_USE_MALLOC if using malloc is okay. This routine will allocate
 *	an initial buffer of size bufsize for use by the application.
 */

int bopen(void *buf, int bufsize, int flags)
{
	bFlags = flags;

#ifdef BASTARD_TESTING
	srand(time(0L));
#endif /* BASTARD_TESTING */

/*
 *	If bopen already called by a shared process, just increment the count
 *	and return;
 */
	if (++bopenCount > 1) {
		return 0;
	}

	if (buf == NULL) {
		if (bufsize == 0) {
			bufsize = B_DEFAULT_MEM;
		}
#ifdef IRIX
		bufsize = ROUNDUP4(bufsize);
#endif
		if ((buf = malloc(bufsize)) == NULL) {
			return -1;
		}
#ifdef B_STATS
		bStatsMemMalloc += bufsize;
#endif
	} else {
		bFlags |= B_USER_BUF;
	}

	bFreeSize = bFreeLeft = bufsize;
	bFreeBuf = bFreeNext = buf;
	memset(bQhead, 0, sizeof(bQhead));
#if (defined (B_FILL) || defined (B_VERIFY_CAUSES_SEVERE_OVERHEAD))
	bFillBlock(buf, bufsize);
#endif
#ifdef B_STATS
	bStackStart = &buf;
#endif
#ifdef B_VERIFY_CAUSES_SEVERE_OVERHEAD
	verifyFreeBlock(buf, bufsize);
#endif
	return 0;
}

/******************************************************************************/
/*
 *	Close down the balloc module and free all malloced memory.
 */

void bclose()
{
#ifdef B_VERIFY_CAUSES_SEVERE_OVERHEAD
	verifyBallocSpace();
#endif
	if (--bopenCount <= 0 && !(bFlags & B_USER_BUF)) {
		free(bFreeBuf);
		bopenCount = 0;
	}
}

/******************************************************************************/
/*
 *	Allocate a block of the requested size. First check the block 
 *	queues for a suitable one.
 */

void *balloc(B_ARGS_DEC, int size)
{
	bType	*bp;
	int		q, memSize;

/*
 *	Call bopen with default values if the application has not yet done so
 */
	if (bFreeBuf == NULL) {
		if (bopen(NULL, B_DEFAULT_MEM, 0) < 0) {
			return NULL;
		}
	}
#ifdef B_VERIFY_CAUSES_SEVERE_OVERHEAD
	verifyBallocSpace();
#endif
	if (size < 0) {
		return NULL;
	}

#ifdef BASTARD_TESTING
	if (rand() == 0x7fff) {
		return NULL;
	}
#endif /* BASTARD_TESTING */


	memSize = ballocGetSize(size, &q);

	if (q >= B_MAX_CLASS) {
/*
 *		Size if bigger than the maximum class. Malloc if use has been okayed
 */
		if (bFlags & B_USE_MALLOC) {
#ifdef B_STATS
			bstats(0, NULL);
#endif
#ifdef IRIX
			memSize = ROUNDUP4(memSize);
#endif
			bp = (bType*) malloc(memSize);
			if (bp == NULL) {
				traceRaw(T("B: malloc failed\n"));
				return NULL;
			}
#ifdef B_STATS
			bStatsMemMalloc += memSize;
#endif
#if (defined (B_FILL) || defined (B_VERIFY_CAUSES_SEVERE_OVERHEAD))
			bFillBlock(bp, memSize);
#endif

		} else {
			traceRaw(T("B: malloc failed\n"));
			return NULL;
		}

/*
 *		the u.size is the actual size allocated for data
 */
		bp->u.size = memSize - sizeof(bType);
		bp->flags = B_MALLOCED;

	} else if ((bp = bQhead[q]) != NULL) {
/*
 *		Take first block off the relevant q if non-empty
 */
		bQhead[q] = bp->u.next;
#ifdef B_VERIFY_CAUSES_SEVERE_OVERHEAD
		verifyFreeBlock(bp, q);
#endif
#if (defined (B_FILL) || defined (B_VERIFY_CAUSES_SEVERE_OVERHEAD))
		bFillBlock(bp, memSize);
#endif
		bp->u.size = memSize - sizeof(bType);
		bp->flags = 0;

	} else {
		if (bFreeLeft > memSize) {
/*
 *			The q was empty, and the free list has spare memory so 
 *			create a new block out of the primary free block
 */
			bp = (bType*) bFreeNext;
#ifdef B_VERIFY_CAUSES_SEVERE_OVERHEAD
			verifyFreeBlock(bp, q);
#endif
			bFreeNext += memSize;
			bFreeLeft -= memSize;
#if (defined (B_FILL) || defined (B_VERIFY_CAUSES_SEVERE_OVERHEAD))
			bFillBlock(bp, memSize);
#endif
			bp->u.size = memSize - sizeof(bType);
			bp->flags = 0;

		} else if (bFlags & B_USE_MALLOC) {
#ifdef B_STATS
			static int once = 0;
			if (once++ == 0) {
				bstats(0, NULL);
			}
#endif
/*
 *			Nothing left on the primary free list, so malloc a new block
 */
#ifdef IRIX
			memSize = ROUNDUP4(memSize);
#endif
			if ((bp = (bType*) malloc(memSize)) == NULL) {
				traceRaw(T("B: malloc failed\n"));
				return NULL;
			}
#ifdef B_STATS
			bStatsMemMalloc += memSize;
#endif
#if (defined (B_FILL) || defined (B_VERIFY_CAUSES_SEVERE_OVERHEAD))
			bFillBlock(bp, memSize);
#endif
			bp->u.size = memSize - sizeof(bType);
			bp->flags = B_MALLOCED;

		} else {
			traceRaw(T("B: malloc failed\n"));
			return NULL;
		}
	}

#ifdef B_STATS
	bStatsAlloc(B_ARGS, bp, q, memSize);
#endif
	bp->flags |= B_INTEGRITY;

/*
 *	The following is a good place to put a breakpoint when trying to reduce
 *	determine and reduce maximum memory use.
 */
#if 0
#ifdef B_STATS
	if (bStatsBallocInUse == bStatsBallocMax) {
		bstats(0, NULL);
	}
#endif
#endif
	return (void*) ((char*) bp + sizeof(bType));
}

/******************************************************************************/
/*
 *	Free a block back to the relevant free q. We don't free back to the O/S
 *	or run time system unless the block is greater than the maximum class size.
 *	We also do not coalesce blocks.
 */

void bfree(B_ARGS_DEC, void *mp)
{
	bType	*bp;
	int		q, memSize;

#ifdef B_VERIFY_CAUSES_SEVERE_OVERHEAD
	verifyBallocSpace();
#endif
	bp = (bType*) ((char*) mp - sizeof(bType));

	a_assert((bp->flags & B_INTEGRITY_MASK) == B_INTEGRITY);

	if ((bp->flags & B_INTEGRITY_MASK) != B_INTEGRITY) {
		return;
	}

	memSize = ballocGetSize(bp->u.size, &q);

#ifdef B_VERIFY_CAUSES_SEVERE_OVERHEAD
	verifyUsedBlock(bp,q);
#endif
#ifdef B_STATS
	bStatsFree(B_ARGS, bp, q, bp->u.size+sizeof(bType));
#endif
	if (bp->flags & B_MALLOCED) {
		free(bp);
		return;
	}
		
#ifdef B_VERIFY_CAUSES_SEVERE_OVERHEAD
	bFillBlock(bp, memSize);
#endif

/*
 *	Simply link onto the head of the relevant q
 */
	bp->u.next = bQhead[q];
	bQhead[q] = bp;

	bp->flags = B_FILL_WORD;
}

/******************************************************************************/
/*
 *	Safe free
 */

void bfreeSafe(B_ARGS_DEC, void *mp)
{
	if (mp) {
		bfree(B_ARGS, mp);
	}
}

/******************************************************************************/
#ifdef UNICODE
/*
 *	Duplicate a string, allow NULL pointers and then dup an empty string.
 */

char *bstrdupA(B_ARGS_DEC, char *s)
{
	char	*cp;
	int		len;

	if (s == NULL) {
		s = "";
	}
	len = strlen(s) + 1;
	if (cp = balloc(B_ARGS, len)) {
		strcpy(cp, s);
	}
	return cp;
}

#endif /* UNICODE */
/******************************************************************************/
/*
 *	Duplicate an ascii string, allow NULL pointers and then dup an empty string.
 *	If UNICODE, bstrdup above works with wide chars, so we need this routine
 *	for ascii strings. 
 */

char_t *bstrdup(B_ARGS_DEC, char_t *s)
{
	char_t	*cp;
	int		len;

	if (s == NULL) {
		s = T("");
	}
	len = gstrlen(s) + 1;
	if ((cp = balloc(B_ARGS, len * sizeof(char_t))) != NULL) {
		gstrcpy(cp, s);
	}
	return cp;
}

/******************************************************************************/
/*
 *	Reallocate a block. Allow NULL pointers and just do a malloc.
 *	Note: if the realloc fails, we return NULL and the previous buffer is 
 *	preserved.
 */

void *brealloc(B_ARGS_DEC, void *mp, int newsize)
{
	bType	*bp;
	void	*newbuf;

	if (mp == NULL) {
		return balloc(B_ARGS, newsize);
	}
	bp = (bType*) ((char*) mp - sizeof(bType));
	a_assert((bp->flags & B_INTEGRITY_MASK) == B_INTEGRITY);

/*
 *	If the allocated memory already has enough room just return the previously
 *	allocated address.
 */
	if (bp->u.size >= newsize) {

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成人理论电影网| 精品国产91乱码一区二区三区| 青娱乐精品在线视频| 国产欧美一区在线| 欧美一级电影网站| 欧美性生活大片视频| 不卡的av电影| k8久久久一区二区三区| 福利电影一区二区| 岛国精品一区二区| 欧美一区二区三区爱爱| 日韩欧美中文一区二区| 一区二区欧美精品| 一级中文字幕一区二区| 成人午夜看片网址| 久久综合中文字幕| 国产精品天干天干在观线| 国产精品国产自产拍高清av王其| 欧美激情综合五月色丁香| 亚洲欧洲无码一区二区三区| 1024国产精品| 成人午夜电影久久影院| 日韩精品中文字幕在线一区| 国产精品网站在线| 国产九色精品成人porny| 国产精品123区| 色综合久久中文字幕| 在线视频你懂得一区| 欧美剧情电影在线观看完整版免费励志电影 | 在线一区二区三区做爰视频网站| 色先锋aa成人| 日韩一区日韩二区| 91麻豆产精品久久久久久| 欧美日韩精品一区二区三区四区| 日韩欧美亚洲另类制服综合在线| 亚洲大片精品永久免费| 精品午夜久久福利影院| 91无套直看片红桃| 亚洲人成在线观看一区二区| 欧美aaaaaa午夜精品| 欧美一区二区视频在线观看| 日本美女一区二区三区| 成人性生交大片免费看中文| 久久九九全国免费| 婷婷久久综合九色综合伊人色| 国产麻豆日韩欧美久久| 欧美日韩视频一区二区| 国产欧美日韩视频一区二区| 国产二区国产一区在线观看| 国产精品乱人伦中文| eeuss鲁片一区二区三区在线观看| 亚洲精品一二三四区| 亚洲高清不卡在线观看| 国产在线精品一区二区夜色| 91香蕉视频mp4| 亚洲国产精品久久不卡毛片| 欧美电影一区二区三区| 精品一区二区三区av| 国产日韩欧美精品在线| 色噜噜久久综合| 免费成人结看片| 久久精品男人的天堂| 色综合天天做天天爱| 久久免费精品国产久精品久久久久| 亚洲黄色在线视频| 欧美videossexotv100| 亚洲3atv精品一区二区三区| 精品国产乱码久久久久久图片| 国产1区2区3区精品美女| 亚洲另类色综合网站| 日韩欧美电影在线| www.欧美色图| 日韩不卡手机在线v区| 国产日韩欧美精品在线| 欧美怡红院视频| 国产一区二区不卡| 一区二区久久久久久| 欧美精品一区二区三区四区| 97超碰欧美中文字幕| 欧美高清在线一区| 91麻豆精品国产无毒不卡在线观看| 亚洲欧美另类久久久精品2019| 日韩免费视频一区二区| 91在线国产福利| 精品伊人久久久久7777人| 亚洲欧美日韩国产成人精品影院| 日韩欧美国产一区二区在线播放 | 99re这里只有精品6| 亚洲一区二区三区视频在线播放 | 激情五月激情综合网| 亚洲精品国产精品乱码不99| 337p日本欧洲亚洲大胆色噜噜| 色诱视频网站一区| 丁香啪啪综合成人亚洲小说| 高清国产一区二区| 日韩国产精品久久| 亚洲黄色小说网站| 亚洲日本va在线观看| 99久久99久久精品国产片果冻 | 亚洲乱码一区二区三区在线观看| 精品国产三级电影在线观看| 欧美日韩精品专区| 欧美三级电影一区| 91浏览器在线视频| 99久久er热在这里只有精品66| 亚洲免费电影在线| 色哟哟一区二区在线观看| 亚洲激情综合网| 欧美成人三级电影在线| 粉嫩嫩av羞羞动漫久久久| 一区二区在线观看免费视频播放 | 亚洲一区二区精品久久av| 92精品国产成人观看免费| 国产91清纯白嫩初高中在线观看| 蜜臀av性久久久久av蜜臀妖精 | 久久国内精品视频| 日韩天堂在线观看| 91精品国产欧美一区二区| 欧美精品久久一区二区三区| 欧美午夜在线一二页| 在线观看日韩毛片| 欧美日韩aaaaaa| 欧美一区二区三区爱爱| 日韩欧美另类在线| 久久女同精品一区二区| 久久久99精品免费观看| 久久久久国产精品厨房| 国产精品女主播av| 亚洲天堂成人网| 亚洲成a人v欧美综合天堂| 日韩精品亚洲专区| 中文久久乱码一区二区| 国产精品女主播av| 亚洲一区二区三区在线播放| 亚欧色一区w666天堂| 污片在线观看一区二区| 免费av成人在线| 国产精一品亚洲二区在线视频| 成人毛片视频在线观看| 91久久精品一区二区二区| 欧美日韩极品在线观看一区| 日韩一区二区免费在线观看| 久久久精品日韩欧美| 日韩一区欧美一区| 日本欧美韩国一区三区| 国产成人免费视频| 欧洲精品一区二区| 精品国产乱码久久久久久牛牛| 国产亚洲精久久久久久| 亚洲国产三级在线| 精品写真视频在线观看| 日本韩国精品在线| 欧美一区二区私人影院日本| 国产欧美精品一区二区色综合 | 麻豆精品国产91久久久久久| 国产精品自拍一区| 欧美写真视频网站| 久久尤物电影视频在线观看| 亚洲精品欧美激情| 激情五月婷婷综合| 欧美色爱综合网| 日本一区二区三区dvd视频在线| 亚洲精品大片www| 国产一区91精品张津瑜| 色天使久久综合网天天| 国产亚洲女人久久久久毛片| 亚洲永久精品国产| 国产成人自拍高清视频在线免费播放| 91免费小视频| 精品91自产拍在线观看一区| 一区二区三区在线不卡| 国产麻豆精品在线| 91精品国产一区二区三区| 亚洲欧洲日韩在线| 国产麻豆一精品一av一免费| 欧美色大人视频| 亚洲免费伊人电影| 国产成人av电影在线| 在线综合亚洲欧美在线视频| 亚洲欧美日韩综合aⅴ视频| 国产麻豆午夜三级精品| 欧美成人在线直播| 五月开心婷婷久久| 色综合天天性综合| 欧美高清在线精品一区| 国产麻豆精品在线| 亚洲精品在线观| 久久国产精品99精品国产| 欧美一区二区三区四区视频| 亚洲一区自拍偷拍| 91丨九色丨尤物| 国产精品久久久久影院亚瑟| 国产夫妻精品视频| 久久综合999| 精品一区二区三区av| 精品欧美久久久| 蓝色福利精品导航| 2020国产精品自拍| 国产91精品露脸国语对白| 久久亚洲精精品中文字幕早川悠里|