⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bget.h

📁 这是法国Kaleido公司提供了一个手机mmi设计平台
💻 H
字号:
/*

    Interface definitions for bget.c, the memory management package.

*/
#ifndef __BGET__
#define  __BGET__

#ifdef __cplusplus
extern "C" {
#endif // def __cplusplus

/******************************
**    Compilation flags      **
** cf. bget.cpp to get all   **
** their definitions         **
******************************/

// Some useful compilation flags
#define COMPACTRACE
	/* To trace compaction actions */
#define EXPTRACE
	/* To trace expansion actions */



//#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   4		      
					 /* 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. */

#define BECtl	    1		      
					 /* Define this symbol to enable the
					 bectl() function for automatic
					 pool space control.  */


/****************************
** A few basic definitions **
****************************/

typedef long bufsize;
typedef int  memsize;  /* Type for size arguments to memxxx() functions such as memcmp(). */

/* 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. */
};
#define BH(p)	((struct bhead *) (p))

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


/*  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))


/****************************
**     Basic C API         **
****************************/

void    bgetDebug(); 
void	bpool	    (void *buffer, bufsize len);
void   *bget	    (bufsize size);
void   *bgetz	    (bufsize size);
void   *bgetr	    (void *buffer, bufsize newsize);
void	brel	    (void *buf);
void	bectl	    (int (*compact)(bufsize sizereq, int sequence),
		       void *(*acquire)(bufsize size),
		       void (*release)(void *buf), bufsize pool_incr);
void	bstats	    (bufsize *curalloc, bufsize *totfree, bufsize *maxfree,
		       long *nget, long *nrel);
void	bstatse     (bufsize *pool_incr, long *npool, long *npget,
		       long *nprel, long *ndget, long *ndrel);
void	bufdump     (void *buf);
void	bpoold	    (void *pool, int dumpalloc, int dumpfree);
int 	bpoolv	    (void *pool);
void 	bgetInit    (void* memoryBloc, int blocSize);


/****************************
**     Basic C API         **
****************************/

struct BGetPool {
#ifdef BECtl
		/* Automatic expansion block management functions */
		bufsize exp_incr;	      /* Expansion block size */
		bufsize pool_len;	      /* 0: no bpool calls have been made
									 -1: not all pool blocks are
										 the same size
									 >0: (common) block size for all
										 bpool calls made so far  */
#endif
#ifdef BufStats
		bufsize totalloc;	      /* Total space currently allocated */
		bufsize maxalloc; /* max space ever allocated */
		long numget;
		long numrel;  /* Number of bget() and brel() calls */
#ifdef BECtl
		long numpblk; /* Number of pool blocks */
		long numpget;
		long numprel; /* Number of block gets and rels */
		long numdget;
		long numdrel; /* Number of direct gets and rels */
#endif /* BECtl */
#endif /* BufStats */
		struct bfhead freelist;  // List of free buffers 
};


/* 
 * This variable is the only global data now used in BGet. It is used by all the
 * functions needing to access tot he pools.
 * It is possible to re-assign it in the calling application in order to manage
 * multiple memory pools.
 */
extern BGetPool* globalPool;

#ifdef __cplusplus
}
#endif // def __cplusplus


#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -