mbrk.c

来自「c库的部分源代码 用惯了操作系统提供的内存api,你是否了解系统的运行机制,这是」· C语言 代码 · 共 22 行

C
22
字号
/****************************************************************
	Copyright 1988 Software Development Systems, Inc.

	This is the default mbrk() function, used with malloc()
	and calloc().  This mbrk() will succeed the first time
	it gets a request for a memory section with no more than
	_brksz bytes, and in that case returns the section
	indicated by _brkp,_brksz.  All other times this
	function returns 0.  The code in "start.s" initializes
	_brkp,_brksz to the address and size of the region
	"malloc" declared in the link specification file "spec".
****************************************************************/
#include "alloc.h"
extern void *_brkp;
extern long _brksz;

char *mbrk( long size, long *realsize ) {
    if ( size > _brksz ) return 0;
    *realsize = _brksz;
    _brksz = 0;
    return _brkp; }

⌨️ 快捷键说明

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