memory.c

来自「Ripper 分类算法」· C语言 代码 · 共 40 行

C
40
字号
#include <stdio.h>extern char *calloc(unsigned int,int);extern int free(char *);char *safe_calloc(n,size)int n,size;{    char *space;     space = calloc((unsigned)n,(unsigned)size);    if (space==NULL) {	fatal("out of memory");    }    return space;}safe_free(space)char *space;{    free(space);}#ifdef TESTmain(){    int n=999,s=12;    int c;        for (c=0;safe_calloc(n,s)!=NULL;c++)      ;    printf("allocated %d times\n",c);}fatal(str)char *str;{    fprintf(stderr,str);}#endif

⌨️ 快捷键说明

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