📄 dy4mmsheap.h
字号:
/********************************************************************************* Filename: dy4mmsHeap.h** Copyright 2003 by DY4 Systems. All Rights Reserved.** Project Name: heap managment utilities** Target: 182** Description: heap managment utilities** Usage:** Log:********************************************************************************//*modification history--------------------Oct 30, 2003 -JS- Created for dy4MMS project01c,02jun03, rgs Changed file name from heap.h to dy4mmsHeap.h.01b,28may03, rgs Standard file header added.01a,01jul01, dy4 Original release.*//*DESCRIPTION:Memory allocation library header file.Heap management constants and data structures.INCLUDE FILES:SEE ALSO:*/#ifndef __INCDY4MMSHEAP__#define __INCDY4MMSHEAP__#ifdef __cplusplusextern "C" {#endif#define NBUCKETS 32#define PLOTALIGN 32L /* PPC_CACHE_LINE_SIZE */#define MAXLENGTH 0x10000000UL#define MINLENGTH (sizeof (plotHdr) + sizeof (plotFtr))#define ISALIGNED(p) (((unsigned long)(p) & (PLOTALIGN-1)) == 0)#define PLOT_STATUS_FREE 0xba5eba11#define PLOT_STATUS_BUSY 0xcabba6e5/********** * * Heaps are divided into "plots". Plots have headers and * footers. Headers are linked together forming a doubly * linked list. Headers either exist in a free list, or * in an "owned" list. * **********/ typedef struct DLLHDR{ struct DLLHDR *next; struct DLLHDR *prev; int padding[6]; /* align to cache line size */} dy4DllHdr;/******** * * A HEAP of memory is a block of memory divided into plots. * The heap contains linked lists, organized by size, of * free plots within the heap. The heap structure also * contains heap start and end addresses for validation. * ********/typedef struct _dy4mms_heap{ void *startAddr; void *endAddr; void *endAddrRound; unsigned long nbytes; int padding[4]; /* align to cache line size */ dy4DllHdr freeLists[NBUCKETS];} DY4MMS_HEAP;/********** * * A plot of memory is a random-size area within a heap. * Each plot has a header and a footer. A plot can be * allocated or free. * * The next and prev pointers form a doubly linked list. * A plot will either live in a free list, or in an "owned" * list (i.e., owned by a task or something). * * Home points to the heap from which the plot was * allocated. Length in the header and footer must * match. * ********/typedef struct PLOTHDR{ dy4DllHdr links; /* 2 pointers */ struct PLOTFTR *ftr; /* -> footer */ unsigned long length; /* incl. header, footer */ int padding[6]; /* align to cache line size */} plotHdr;typedef struct PLOTFTR{ struct PLOTHDR *header; DY4MMS_HEAP *home; unsigned long status; unsigned long length; int padding[4]; /* align to cache line size */} plotFtr;/* ------------local function prototypes------------ */void dy4DllAdd(dy4DllHdr *p, dy4DllHdr *h);void dy4DllRemove(dy4DllHdr *p);void dy4DllAddFirst( dy4DllHdr *blk, dy4DllHdr *queue );long nToBucket(unsigned long n);void plotSetup(void *mptr, unsigned long length, DY4MMS_HEAP *home, unsigned long status);int plotValid(plotHdr *h);plotHdr *endPtrToHdr(void *endAddr);void plotFreeListAdd(plotHdr *p, DY4MMS_HEAP *home);plotHdr *plotMerge(plotHdr *p);plotHdr *plotSplit(plotHdr *p, unsigned long length1);unsigned long plotAlign(plotHdr *p, unsigned long align);plotHdr *heapSearch(unsigned long length, unsigned long align, DY4MMS_HEAP *hPtr);plotHdr *heapAlloc(unsigned long length, long align, DY4MMS_HEAP *home);/* ------------external function prototypes------------ */void *heapMallocAligned(unsigned long length, unsigned long align, DY4MMS_HEAP *hPtr);void *heapMalloc(unsigned long length, DY4MMS_HEAP *hPtr);void *heapCalloc(unsigned long nitems, unsigned long nbytes, DY4MMS_HEAP *hPtr);void heapFree(void *p);void *heapResize(void *p, unsigned long newsize);int heapAugment(void *start, unsigned long nbytes, DY4MMS_HEAP *heapPtr);void *heapInit(DY4MMS_HEAP *heapPtr, void *start, unsigned long nbytes);long heapTest(DY4MMS_HEAP *hPtr, unsigned long *nRegions_p, unsigned long *freeBytes_p, unsigned long *largest_p);/* ------------ END OF FILE --------------------------- */#ifdef __cplusplus}#endif#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -