资源简介
卡内基梅隆大学15213第六个malloc lab 用seglist写的,89分代码
代码片段和文件信息
/*
* mm.c
*
* AndrewID : jieruil
* Name : Jierui Liu
* Approach : put free blocks into different free list by their sizes. Each free * list‘s header is saved at the heap‘s address. This program gives us 18 lists
* so that the front 18 words of the heap address is the 18 headers.
*
*/
#include
#include
#include
#include
#include
#include “mm.h“
#include “memlib.h“
/* If you want debugging output use the following macro. When you hand
* in remove the #define DEBUG line. */
#define DEBUG
#ifdef DEBUG
# define dbg_printf(...) printf(__VA_ARGS__)
#else
# define dbg_printf(...)
#endif
/* do not change the following! */
#ifdef DRIVER
/* create aliases for driver tests */
#define malloc mm_malloc
#define free mm_free
#define realloc mm_realloc
#define calloc mm_calloc
#endif /* def DRIVER */
/* basic comstants and macros*/
#define WSIZE 4
#define DSIZE 8
#define CHUNKSIZE (1 << 12)
#define MAX(x y) ((x) > (y)? (x) : (y))
/*PACK a size and allocate bit into a word*/
#define PACK(size alloc) ((size) | (alloc))
/* read and write a word at address p*/
#define GET(p) (*(unsigned int *)(p))
#define PUT(p val) (*(unsigned int *)(p) = (val))
/* read and write a pointer at address p */
#define GET_PTR(p) ((unsigned int *)(long)(GET(p)))
#define PUT_PTR(p ptr) (*(unsigned int *)(p) = ((long)ptr))
/* read the size and allocated fields 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 previous blocks*/
#define NEXT_BLKP(bp) ((char *)(bp) + GET_SIZE(((char *)(bp) - WSIZE)))
#define PREV_BLKP(bp) ((char *)(bp) - GET_SIZE(((char *)(bp) - DSIZE)))
/* the size of the block in each free list */
#define SIZE1 (1 << 4)
#define SIZE2 (1 << 5)
#define SIZE3 (1 << 6)
#define SIZE4 (1 << 7)
#define SIZE5 (1 << 8)
#define SIZE6 (1 << 9)
#define SIZE7 (1 << 10)
#define SIZE8 (1 << 11)
#define SIZE9 (1 << 12)
#define SIZE10 (1 << 13)
#define SIZE11 (1 << 14)
#define SIZE12 (1 << 15)
#define SIZE13 (1 << 16)
#define SIZE14 (1 << 17)
#define SIZE15 (1 << 18)
#define SIZE16 (1 << 19)
#define SIZE17 (1 << 20)
#define LIST_NUM 18 /* the number of free lists */
/* global variable */
static char *heap_listp;
/* single word (4) or double word (8) alignment */
#define ALIGNMENT 8
/* rounds up to the nearest multiple of ALIGNMENT */
#define ALIGN(p) (((size_t)(p) + (ALIGNMENT-1)) & ~0x7)
#define SIZE_T_SIZE (ALLGN(sizeof(size_t)))
/* function declaration */
static void *extend_heap(size_t words);
static void *coalesce(void *bp);
static void *find_fit(size_t tsize);
static void place(void *bp size_t tsize);
static void list_insert(void *bp);
void list_delete(void *bp);
int getListIndex(size_t size);
/*
*
- 上一篇:四元数与三维旋转,Krasjet
- 下一篇:rational_perm.dat
评论
共有 条评论