不一发生错误的内存分配器_macula7的空间

alloc.h//接口

#include<stdlib.h>

#define malloc

#define MALLOC(num,type) (type *)alloc((num)*sizeof(type))

extern void *alloc(size_t size);

alloc.c//实现

#include <stdio.h>

#include "alloc.h"

#undef malloc

void * alloc(size_t size)

{

void *new_mem;

new_mem=malloc(size);

if(new_mem==NULL){

printf("out of memory\n");

exit(1);

}

return new_mem;

}

a_client.c//使用

#include "alloc.h"

void function(){

int *new_memory;

new_memory=MALLOC(25,int);

}



郑重声明:资讯 【不一发生错误的内存分配器_macula7的空间】由 发布,版权归原作者及其所在单位,其原创性以及文中陈述文字和内容未经(企业库qiyeku.com)证实,请读者仅作参考,并请自行核实相关内容。若本文有侵犯到您的版权, 请你提供相关证明及申请并与我们联系(qiyeku # qq.com)或【在线投诉】,我们审核后将会尽快处理。
—— 相关资讯 ——