看前先点赞,拒绝白嫖!
#ifndef __memory__
#define __memory__
#ifndef calloc
#include<stdlib.h>
#endif
typedef bool mem;
template<typename _void_>
void *memory(char*ch_mem,_void_*item,int q){ //ch_mem==“free”free(item) else malloc(q)
if(ch_mem==("free")){
free(item);
return NULL;
}
if(item==NULL){
return NULL;
}
return malloc(q);
}
template<typename _mem_>
mem inmem(_mem_*in_mem){
if(*in_mem){
return true;
}else{
return false;
}
}
#endif
这是一个头文件,memory是free与malloc的集合,
inmem是判断指针in_mem所指向的是否为空。
我不知道是否会内存泄露,望告知......