mystdlib.c
来自「压缩包里面的都是精致的基本C语言小程序」· C语言 代码 · 共 57 行
C
57 行
#include <stdio.h>#include <stdlib.h>#include <assert.h>#include "error.h"#include "mystdlib.h"long usedMemory = 0;void *checkedMalloc (int size){ if (size < 0) exception ("what going on here?\n"); //printf ("size=%d\n", size); void *temp = malloc (size); if (!temp) { //printf ("%d\n", size); printf ("used memory: %lfG\n", usedMemory*1.0/1024/1024/1024); exception ("no memory!\n"); } usedMemory += size; return temp;}void checkedFree (void *p){ if (p) { //printf ("checked freeing\n"); free (p); } else error ("try to free null pointers\n");}int checkedSystem (const char *s){ return system (s);}void *checkedRealloc (void *p, unsigned int size){ void *temp = realloc (p, size); assert (temp); return temp;}void memoryStatus (){ printf ("memory used = %lfG\n", usedMemory*1.0/1024/1024/1024);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?