User:Antigng-bot/mem

#include <stdio.h>
#include <stdlib.h>
#include <process.h> 
#include <windows.h>
#define MEM_MAX_RETRY 5
#define MEM_SLEEP 5000

void *s_malloc(size_t size)
{
	void *p;
	if(p=malloc(size)) return p;
	else
	{
		int count=0;
		for(;count<MEM_MAX_RETRY;count++)
		{
			Sleep(MEM_SLEEP);
			if(p=malloc(size)) return p;
		}
		fprintf(stderr,"Crash no memory.\n");
		exit(-2);
		return NULL;
	}
}
void *s_calloc(size_t size,size_t num)
{
	void *p;
	if(p=calloc(size,num)) return p;
	else
	{
		int count=0;
		for(;count<MEM_MAX_RETRY;count++)
		{
			Sleep(MEM_SLEEP);
			if(p=calloc(size,num)) return p;
		}
		fprintf(stderr,"Crash no memory.\n");
		exit(-2);
		return NULL;
	}
}
void s_free(void *p)
{
	if(p) free(p);
	return;
}