资源简介
哈工大计算机系统Lab8 报告+源代码,供学弟学妹参考。
代码片段和文件信息
/*
* 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 = {
/* Team name */
“hzj1173710108“
/* First member‘s full name */
“hzj“
/* First member‘s email address */
“@ZJ“
/* Second member‘s full name (leave blank if none) */
““
/* Second member‘s email address (leave blank if none) */
““
};
/* 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 /*Double word size*/
#define CHUNKSIZE (1<<12) /*the page size in bytes is 4K*/
#define MAX(xy) ((x)>(y)?(x):(y))
#define PACK(sizealloc) ((size) | (alloc))
#define GET(p) (*(unsigned int *)(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)
#define NEXT_BLKP(bp) ((char *)(bp)+GET_SIZE(((char *)(bp)-WSIZE)))
#define PREV_BLKP(bp) ((char *)(bp)-GET_SIZE(((char *)(bp)-DSIZE)))
static void *extend_heap(size_t words);
static void *coalesce(void *bp);
static void *find_fit(size_t size);
static void place(void *bpsize_t asize);
static char *heap_listp = 0;
/*
* mm_init - initialize the malloc package.
* The return value should be -1 if there was a problem in performing the initialization 0 otherwise
*/
int mm_init(void)
{
if((heap_listp = mem_sbrk(4*WSIZE))==(void *)-1){
return -1;
}
PUT(heap_listp0);
PUT(heap_listp+(1*WSIZE)PACK(DSIZE1));
PUT(heap_listp+(2*WSIZE)PACK(DSIZE1));
PUT(heap_listp+(3*WSIZE)PACK(01));
heap_listp += (2*WSIZE);
if(extend_heap(CHUNKSIZE/WSIZE)==NULL){
return -1;
}
return 0;
}
static void *extend_heap(size_t words){
char *bp;
size_t size;
size = (words%2) ? (words+1)*WSIZE : words*WSIZE;
if((long)(bp=mem_sbrk(size))==(void *)-1)
return NULL;
PUT(HDRP(bp)PACK(size0));
PUT(FTRP(bp)PACK(size0));
PUT(HDRP(NEXT_BLKP(bp))PACK(01));
return coalesce(
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1228026 2018-12-29 20:30 1173710108 侯泽健.doc
文件 6161 2018-12-29 19:32 mm.c
----------- --------- ---------- ----- ----
1234187 2
- 上一篇:Pla
yerPrefs可视化工具 - 下一篇:日语面试集锦
相关资源
- iot-dc3-architecture.pptx
- 计算机系统基础袁春风著.txt
- 哈工大sse题库
- PageRank&HITS算法
- 哈工大2018考研录取
- solution for computer architecture 5th edition
- 哈工大2014年数据挖掘期末试题
- 哈工大软件质量保障与测试2018试题
- 深入理解计算机系统原书第三版中文
- 厦门大学计算机系统结构(复习必过
- 南京大学计算机系计算机系统基础期
- 哈工大同义词词林.zip
- IBM Rational Software Architect (RSA) 9.0 破
- 哈工大操作系统实验:字符显示的控
- 哈工大计科《计算机网络spoc》答案
- 深入理解计算机系统原书第三版超高
- 哈工大_数据结构与算法视频教程48集
- 哈工大计科数据库实验四
- 哈工大系统安全实验1实验报告参考
- Reg_Calculator_v1.67.xlsx
- 哈工大软件构造实验三、四
- 哈工大操作系统实验五
- 哈工大 编译原理作业
- 哈工大数理逻辑历年考试题
- 哈工大微电子器件教材答案
- hathitrust 工具
- hathitrust.zip
- 哈工大计算机系统实验实验八
- 哈工大计算机系统实验PPT
- 哈工大 EDA课程设计 verilog编程 数字秒
评论
共有 条评论