⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ps_mem.h

📁 我自己写的一个文本阅读器
💻 H
字号:
#include "ps_def.h"

#ifndef PS_MEM_H
#define PS_MEM_H

#define PS_DEBUG_MEMORY

#ifdef __cplusplus
extern "C"
{
#endif

#define ps_free2null( p )  if( (p) != PSS_NULL ) { psFree( (p) ); (p) = PSS_NULL; }

#ifdef PS_DEBUG_MEMORY

#define ASSERT_STRING "THIS IS THE HELL!HOW HAVE I COME HERE?!\n"

extern const ps_char *g_cur_file_name;
extern ps_u32 g_cur_line;

void *ps_memMalloc( ps_u32 size );
void *ps_memCalloc( ps_u32 size, ps_u32 num  );
void *ps_memRealloc( void *ptr,ps_u32 size );
void ps_memFree( void * ptr );
void ps_memlist_DBGMemoryLeak(void);
void debugmem_report_size(void);

#define psMalloc(x)		( g_cur_file_name = __FILE__, g_cur_line = __LINE__, ps_memMalloc((x)) )
#define psMallocT(x)	( g_cur_file_name = __FILE__, g_cur_line = __LINE__, (x*)ps_memMalloc(sizeof(x)) )
#define psCalloc(a, b)	( g_cur_file_name = __FILE__, g_cur_line = __LINE__, ps_memCalloc((a), (b)) )
#define psRealloc(p, x)	( g_cur_file_name = __FILE__, g_cur_line = __LINE__, ps_memRealloc((p), (x)) )
#define psFree(p)		( g_cur_file_name = __FILE__, g_cur_line = __LINE__, ps_memFree( (p) ) ) 

#else //PS_DEBUG_MEMORY
#define psMalloc(x)		malloc((x))
#define psMallocT(x)	(x *)malloc(sizeof(x))
#define psCalloc(a, b)	calloc((a), (b))
#define psRealloc(p, x)	realloc((p), (x))
#define psFree(p)		free( (p) ) 

#define ps_memlist_DBGMemoryLeak()
#define debugmem_report_size()
#endif

#ifdef ECOS
	#include <cyg/kernel/kapi.h>
	#include <cyg/hal/drv_api.h>

	cyg_mutex_t				ps_mem_mutex;
	#define __LOCK__		cyg_mutex_lock(&ps_mem_mutex)
	#define __UNLOCK__		cyg_mutex_unlock(&ps_mem_mutex)
	#define __INITLOCK__	cyg_mutex_init(&ps_mem_mutex )
	#define __DESTROYLOCK__	cyg_mutex_destroy(&ps_mem_mutex)

	#define PS_ASSERT		ASSERT
#endif

#ifdef CONEXANT
	#include <assert.h>	
	#define PS_ASSERT		assert
#else
	#define __LOCK__		
	#define __UNLOCK__		
	#define __INITLOCK__	
	#define __DESTROYLOCK__
	#define PS_ASSERT		printf
#endif 

#ifdef __cplusplus
}
#endif


#endif  /* PS_MEM_H*/


⌨️ 快捷键说明

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