All pastes #632339 Raw Edit

Anonymous

public c v1 · immutable
#632339 ·published 2007-07-24 20:04 UTC
rendered paste body
#define WSIZE       4       /* word size (bytes) */#define DSIZE       8       /* doubleword size (bytes) */#define CHUNKSIZE   (1<<12) /* initial heap size (bytes) */#define OVERHEAD    8       /* overhead of header and footer (bytes) */#define MAX(x, y)   ((x) > (y) ? (x) : (y))/* Pack a size and allocated bit into a word */#define PACK(size, alloc) ((size) | (alloc))/* Read and write a word at address p */#define GET(p)      (*(size_t *)(p))#define PUT(p, val) (*(size_t *)(p) = (val))/* Read the size and allocated feilds from address p */#define GET_SIZE(p)     (GET(p) & ~0x7)#define GET_ALLOC(p)    (GET(p) & 0x1)/* Given block ptr bp, compute address of its header and footer */#define HDRP(bp)    ((char *)(bp) - WSIZE)#define FTRP(bp)    ((char *)(bp) + GET_SIZE(HDRP(bp)) - DSIZE)/* Given block ptr bp, compute address of next and prev blocks */#define NEXT_BLKP(bp)   ((char *)(bp) + GET_SIZE(((char *)(bp) - WSIZE)))#define PREV_BLKP(bp)   ((char *)(bp) - GET_SIZE(((char *)(bp) - DSIZE)))/* Function prototypes */extern int my_init(void);extern static void *extend_heap(size_t words);extern void my_free(void *bp);extern void my_malloc(size_t size);extern static void *coalesce(void *bp);extern static void *find_fit(size_t asize);extern static void place(void *bp, size_t asize);/* global variable, marking first block of the heap */extern static char *heap_listp;