📄 gstdmem.c
字号:
/*
* Copyright (C) Obigo AB, 2002-2005.
* All rights reserved.
*
* This software is covered by the license agreement between
* the end user and Obigo AB, and may be
* used and copied only in accordance with the terms of the
* said agreement.
*
* Obigo AB assumes no responsibility or
* liability for any errors or inaccuracies in this software,
* or any consequential, incidental or indirect damage arising
* out of the use of the software.
*
*/
#include "cansilib.h"
#include "cmnconf.h"
#include "aapicmn.h"
#ifndef USE_G_MALLOC
#include "gmem.h"
typedef struct
{
jmp_buf jmpbuf;
int inside;
#if CMN_LOG_INTERNAL & CMN_LOG_MEMORY
int lognum;
#endif
} MemClient;
static MemClient memClients[CMN_CLIENT_NUMBER];
int gMemGetInside(CmnClientId id)
{
return memClients[id].inside;
}
jmp_buf *gMemGetJmpBuf(CmnClientId id)
{
return &memClients[id].jmpbuf;
}
short gMemInit(CmnClientId id, MemPtr mem, MemSize memSize)
{
id = 0;
mem = 0;
memSize = 0;
return 0;
}
void gMemSetInside(CmnClientId id, int inside)
{
memClients[id].inside = inside;
}
void gMemSetOutside(CmnClientId id)
{
memClients[id].inside = 0;
}
void gMemTerminate(CmnClientId id)
{
id = 0;
}
#if CMN_LOG_INTERNAL & CMN_LOG_MEMORY
MemPtr gMemAlloc(CmnClientId id, MemSize size, const char *filename, int lineno)
#else
MemPtr gMemAlloc(CmnClientId id, MemSize size)
#endif
{
void *p = malloc(size);
#if CMN_LOG_INTERNAL & CMN_LOG_MEMORY
{
const char *s = strrchr (filename, '\\');
if (s == NULL)
{
s = filename;
}
else
{
++s;
}
CMN_LOG_I(("MEM: + %#08x %6d %6d %6d %s (%d)\n",
p, ++memClients[id].lognum, size, id, s, lineno));
}
#endif
if ((p == NULL) && memClients[id].inside)
{
longjmp( memClients[id].jmpbuf, 1);
}
return p;
}
#if CMN_LOG_INTERNAL & CMN_LOG_MEMORY
void gMemFree(CmnClientId id, void *p, const char *filename, int lineno)
#else
void gMemFree (CmnClientId id, void *p)
#endif
{
#if CMN_LOG_INTERNAL & CMN_LOG_MEMORY
if (p != NULL)
{
const char *s = strrchr (filename, '\\');
if (s == NULL)
{
s = filename;
}
else
{
++s;
}
CMN_LOG_I(("MEM: - %#08x %6d %6d %s (%d)\n",
p, ++memClients[id].lognum, id, s, lineno));
}
#endif
if (p != NULL)
{
free(p);
}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -