malloc.c

来自「实现一个简单的单进程内核,。该内核启用二级虚拟页表映射」· C语言 代码 · 共 75 行

C
75
字号
/* The 15-410 C Library * malloc.c *  * Zachary Anderson(zra) */#include "mm_malloc.h"#include <stdlib.h>#include <string.h> /* for bzero *//* * Has the mm_malloc library been initialized yet? */static unsigned int inited = 0;/* * wrapper around the mm_malloc library mm_malloc */void *_malloc( size_t __size ){	if( !inited ) {		mm_init();		inited = 1;	}	return mm_malloc( __size );}/* * calloc implimented with mm_malloc library */void *_calloc( size_t __nelt, size_t __eltsize ){	void *new;        if( !inited ) {                mm_init();                 inited = 1;        }	new = mm_malloc( __nelt * __eltsize );	if( !new ) {		return NULL;	}	bzero( new, __nelt * __eltsize );	return new;}/* * wrapper around the mm_malloc library mm_realloc */void *_realloc( void *__buf, size_t __new_size ){        if( !inited ) {		/* have to malloc before realloc =P */		return NULL;        }	return mm_realloc( __buf, __new_size );}/* * wrapper around the mm_malloc library mm_free */void _free( void *__buf ){	if( !inited ) {		/* hmm. not really anything to free. */		return;	}	mm_free( __buf );}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?