-
大小: 13KB文件類型: .c金幣: 1下載: 0 次發(fā)布日期: 2021-06-08
- 語言: 其他
- 標(biāo)簽: csapp??malloc??lab??原創(chuàng)??
資源簡介
采用seg-list結(jié)構(gòu),易于理解,適合和我一樣的弱渣使用,好好調(diào)參,可以得到93分,我覺得可以接受
代碼片段和文件信息
/*
????ID:1600011090???NAME:Chen?HaoRan
????????????????????MIAN?IDEA:
????I?use?the?seglist?to?complete?it
????First?i?store?40?pointers?in?the?heap?free_head[20]
in?which?free_head[i]?is?the?head?pointer?of?the?rank
i?free_listeach?list?will?contain?the?size?of?[2^i2^(i+1)
block.
????Then?the?free_tail[20]?pointer?to?the?tail?of?20?free_
list.
????For?mallocingi?use?the?first_fit?to?find?a?place?in?the
suitable?listby?testing?we?now?it?can?get?most?scores.Then?
delete?it?from?the?free_list.
????For?freeingi?just?add?it?to?the?free_list.
????For?coalescingdelete?the?neiborhood?free?blocks?from?the
listcombine?themadd?it?to?the?free_list?again.
????Reallock?function?should?tell?the?rank?of?the?oldsize?and
and?the?newsize?to?determine?whether?we?should?copy?the?data?from
old?place?to?a?new?place.
*/
#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?*/
/*
the?macro?below?is?what?i?will?use?in?the?program
the?meaning?of?them?are?easy?to?tell?by?their?names
*/
#define?WSIZE???????4??????
#define?DSIZE???????8??????
#define?BLOCKSIZE???16??????
#define?INFOSIZE????8??????
#define?CHUNKSIZE???0x150?
#define?MAX(x?y)?((x)?>?(y)??(x)?:?(y))??
#define?ALIGNMENT?8
#define?ALIGN(size)?(((size_t)(size)?+?(ALIGNMENT?-?1))?&?~0x7)
#define?PACK(size?alloc)??((size)?|?(alloc))?
#define?GET(p)???????(*(unsigned?int?*)(p))????????????
#define?PUT(p?val)??(*(unsigned?int?*)(p)?=?(val))??
#define?GET_SIZE(p)??(GET(p)?&?~0x7)???????????????????
#define?GET_ALLOC(p)?(GET(p)?&?0x1)??????????????????
#define?HEAD(bp)???????((char?*)(bp)?-?WSIZE)??????????????????????
#define?FOOT(bp)???????((char?*)(bp)?+?GET_SIZE(HEAD(bp))?-?DSIZE)?
#define?NEXT_BLKP(bp)??((char?*)(bp)?+?GET_SIZE(((char?*)(bp)?-?WSIZE)))
#define?PREV_BLKP(bp)??((char?*)(bp)?-?GET_SIZE(((char?*)(bp)?-?DSIZE)))
#define?SIZE(bp)??????(GET_SIZE(HEAD(bp)))
#define?PREV_SIZE(bp)?(GET_SIZE((char?*)(bp)?-?DSIZE))
#define?NEXT_SIZE(bp)?(GET_SIZE((char?*)(bp)?+?SIZE(bp)?-?WSIZE))
#define?ALLOC(bp)?????(GET_ALLOC(HEAD(bp)))
#define?FATHER(bp)??????((char?*)(bp)?-?GET(bp))
#define?CHILD(bp)??????((char?*)(bp)?+?GET((char?*)(bp)?+?WSIZE))
#define?PUT_FATHER(bp?pre)??PUT(bp?(unsigned?int)((char?*)(bp)?-?(char?*)(pre)))
#define?PUT_CHILD(bp?suc)??PUT((char?*)(bp)?+?WSIZE?(unsigned?int)((char?*)(suc)?-?(char?*)(bp)))
#define?ALLNULL?????0
#define?HEADNULL????1
#define?TAILNULL????2
#define?NORMAL??????3
/*?
here?are?the?global?variablepoint?to?the?heapfree_list‘s?
headfree_list‘s?tail
評論
共有 條評論