资源简介
ssd6 第七次实验 内存管理 四川大学软件学院 2018年秋季
代码片段和文件信息
#include
#include
#include “debugmalloc.h“
#include “dmhelper.h“
#include
#define CHECKSUM_PL(pptr) *((int*)(pptr) - 5)
#define LINENUMB_PL(pptr) *((int*)(pptr) - 4)
#define SIZE_PL(pptr) *((int*)(pptr) - 3)
#define FIFENAME_PL(pptr) *((int*)(pptr) - 2)
#define FSTFENCE_PL(pptr) *((int*)(pptr) - 1)
//payload pointer
#define ENDFENCE_PL(pptrsize) *(int*)((char*)(pptr) + (size))
//dual list node
typedef struct DuLNode{
void * pptr; //PayloadPoinTeR
struct DuLNode * prior;
struct DuLNode * next;
}DuLNode DuLList;
DuLList list = {NULL NULL NULL};
int allocated_size = 0;
DuLNode* get_last_node(DuLList *L)
{
DuLNode* temp = L;
while(temp->next != NULL)
temp = temp->next;
return temp;
}
DuLNode* get_specify_node(DuLList *L void* e)
{
DuLNode* temp = L;
while(temp->pptr != e)
temp = temp->next;
if(temp->pptr != e)
return NULL;
else
return temp;
}
int insert_node(DuLList* L void* e)
{
DuLNode* new_node;
DuLNode* last = get_last_node(L);
if(!(new_node = (DuLNode*)malloc(sizeof(DuLNode))))
return 0;
new_node->pptr = e;
new_node->prior = last; new_node->next = NULL;
last->next = new_node;
return 1;
}
int delete_node(DuLList* L void* e)
{
DuLNode* specify;
if(NULL != (specify = get_specify_node(L e)))
{
specify->prior->next = specify->next;
if(specify->next != NULL)
specify->next->prior = specify->prior;
free(specify);
return 1;
}
return 0;
}
//mprt: MallocPoinTeR
void initialize_raw_memory(void* mptr int sizechar *filenameint linenumber)
{
*(int*)mptr = (int)linenumber + (int)filename + (int)size;//checksum
*((int*)mptr+1) = linenumber;
*((int*)mptr+2) = size;
*((int*)mptr+3) = (int)filename;
*((int*)mptr+4) = 0xCCDEADCC; //start fence
*(int*)((char*)mptr + size + 20) = 0xCCDEADCC; //end fence;
}
//pprt: PayloadPoinTeR
void error_check(void* pptr char *filename_free int linenumber_free)
{
DuLNode* node = list.next;
int size = SIZE_PL(pptr);
int checksum = LINENUMB_PL(pptr) + SIZE_PL(pptr) + FIFENAME_PL(pptr);
while(node != NULL){
if(node->pptr == pptr)
break;
node = node->next;
}
if(node == NULL)
error(4 filename_free
- 上一篇:扫描天线 阵列天线 天线方向图
- 下一篇:局域网window机器远程开关机软件
评论
共有 条评论