資源簡介
資源包括:lab說明指導、lab實現代碼及解析(在代碼注釋中)、lab筆記(note文件中)、lab注意事項等,分享給大家

代碼片段和文件信息
/*
?*?mm-naive.c?-?The?fastest?least?memory-efficient?malloc?package.
?*?
?*?In?this?naive?approach?a?block?is?allocated?by?simply?incrementing
?*?the?brk?pointer.??A?block?is?pure?payload.?There?are?no?headers?or
?*?footers.??Blocks?are?never?coalesced?or?reused.?Realloc?is
?*?implemented?directly?using?mm_malloc?and?mm_free.
?*
?*?NOTE?TO?STUDENTS:?Replace?this?header?comment?with?your?own?header
?*?comment?that?gives?a?high?level?description?of?your?solution.
?*/
#include?
#include?
#include?
#include?
#include?
#include?“mm.h“
#include?“memlib.h“
/*********************************************************
?*?NOTE?TO?STUDENTS:?Before?you?do?anything?else?please
?*?provide?your?team?information?in?the?following?struct.
?********************************************************/
team_t?team?=?{
????/*?Your?student_id?*/
????“16307130350“
????/*?Your?full?name?*/
????“王明霞“
????/*?Your?email?address?*/
????“16307130350@fudan.edu.cn“
????/*?leave?blank??*/
????““
????/*?leave?blank?*/
????““
};
/*?single?word?(4)?or?double?word?(8)?alignment?*/
#define?ALIGNMENT?8
/*?rounds?up?to?the?nearest?multiple?of?ALIGNMENT?*/
#define?ALIGN(size)?(((size)?+?(ALIGNMENT-1))?&?~0x7)
#define?SIZE_T_SIZE?(ALIGN(sizeof(size_t)))
#define?WSIZE?4
#define?DSIZE?8??????????
#define?CHUNKSIZE?(1<<12)?//extend?heap?by?this?amount(bytes)
#define?MAX(xy)????((x)>(y)?(x):(y))
#define?PACK(sizealloc)????((size)?|?(alloc))?//pack?a?size?and?allocated?bit?into?a?word
#define?GET(p)??(*(unsigned?int?*)(p))?//read?and?write?a?word?at?address?p
#define?PUT(pval)??(*(unsigned?int?*)(p)?=?(val))
#define?GET_SIZE(p)??(GET(p)?&?~0x7)
#define?GET_ALLOC(p)????(GET(p)?&?0x1)
#define?HDRP(bp)????((char?*)(bp)-WSIZE)
#define?FTRP(bp)????((char?*)(bp)+GET_SIZE(HDRP(bp))-DSIZE)?/*合并方式采取帶邊界標記的合并*/
/*?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)))
#define?PREV_linkNODE_RP(bp)?((char*)(bp))? /*bp的前一個node:pred*/
#define?NEXT_linkNODE_RP(bp)?((char*)(bp)+WSIZE)? /*bp的后一個node:succ*/
?
static?void?*extend_heap(size_t?words);
static?void?*coalesce(void?*bp);
inline?char?*find_free_list_header(size_t?size);
inline?void?delete_from_list(char?*p);
inline?void?insert_to_link(char?*p);
static?void?place(void?*bpsize_t?asize);
static?void*?find_fit(size_t?size);
void*?memcpy_new(void?*Dest?const?void?*Src?size_t?Count);
static?void?*realloc_coalesce(void?*bp?size_t?newSize?int?*bp_not_change);
static?void?realloc_place(void?*bpsize_t?asize);
static?char?*heap_listp?=?NULL;
static?char?*free_list_start?=?NULL;
/*?
?*?mm_init?-?initialize?the?malloc?package.
?*/
int?mm_init(void){
????if((heap_listp?=?mem_sbrk(14*WSIZE))==(void?*)-1)?//使用mem_sbrk請求額外的堆處理器
return?-1;
/*?使用簡單分離存儲?*/
????PUT(heap_
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-11-06?11:46??malloclab全套資料及參考答案\
?????文件???????77983??2018-11-06?11:39??malloclab全套資料及參考答案\malloclab.pdf
?????文件???????14110??2018-11-06?11:39??malloclab全套資料及參考答案\mm_5.0.c
?????文件???????16401??2018-11-06?11:39??malloclab全套資料及參考答案\mm_best_untilnow.c
?????文件????????2423??2018-11-06?11:39??malloclab全套資料及參考答案\mm_initial?(2).c
?????文件??????883371??2018-11-06?11:40??malloclab全套資料及參考答案\report.docx
?????文件???????13238??2018-11-06?11:39??malloclab全套資料及參考答案\standard.c
評論
共有 條評論