📄 oslmemory.c
字号:
/*****************************************************************************
* Copyright Statement:
* --------------------
* This software is protected by Copyright and the information contained
* herein is confidential. The software may not be copied and the information
* contained herein may not be used or disclosed except with the written
* permission of MediaTek Inc. (C) 2005
*
* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
*
* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/
/*******************************************************************************
* Filename:
* ---------
* OslMemory.c
*
* Project:
* --------
* MAUI
*
* Description:
* ------------
*
*
* Author:
* -------
*
*
*==============================================================================
* HISTORY
* Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*------------------------------------------------------------------------------
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
*------------------------------------------------------------------------------
* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*==============================================================================
*******************************************************************************/
/**
* Copyright Notice
* ?2002 - 2003, Pixtel Communications, Inc., 1489 43rd Ave. W.,
* Vancouver, B.C. V6M 4K8 Canada. All Rights Reserved.
* (It is illegal to remove this copyright notice from this software or any
* portion of it)
*/
/**************************************************************
FILENAME : OslMemory.c
PURPOSE : Memory Wrapper
REMARKS : nil
AUTHOR : Neeraj Sharma, Amit Kumar
DATE : Jan' 21, 2003
**************************************************************/
/* Include: MMI header file */
#include "oslmemory.h"
#include "DateTimeType.h"
#include "DateTimeGprot.h"
#include "PixtelDataTypes.h"
#include "StdC.h"
#include "DebugInitDef.h"
#ifdef OSL_MEMORY_DUMP /* if OSL_MEMORY_DUMP is not enabled then don't compile */
#define BUFFER_POOLS 16
#define MEMORY_LIST_LENGTH 50
/*--------------------------------------------------------------------
Data Structure Declerations
-----------------------------------------------------------------------*/
typedef struct oslmemalloc
{ /* info */
S8 fileName[20];
S32 lineNumber;
S32 bytes;
void *ptr;
U8 isAllocated;
} OSLMEMALLOC;
S32 goslMemCount = 0; /* Total Allocated heap mem */
S32 MAX_BUFF = 0;
S32 MaxDynamicMemUsed = 0;
static OSLMEMALLOC memoryList[MEMORY_LIST_LENGTH];
static U16 bufferCount[BUFFER_POOLS];
static U8 memoryListCount = 0;
static U8 MallocFirstTime = 1;
/*--------------------------------------------------------------------
Function Declerations
-----------------------------------------------------------------------*/
void *OslMallocCHK(long nob, char *fileName, int lineNumber, ...);
void OslMfreeCHK(void *frp);
void OslIntMemoryStart();
void OslIntDumpDataInFile(void);
long OslIntMemCounter(void);
/*-------------------------------------------------------------------
Function Name : ByteCounter
Description : This inline function keeps track of heap memory
allocations in bytes
Input : Pointer
Flag : 1 to add no. of bytes
-1 to delete no. of bytes
Output : None
--------------------------------------------------------------------*/
/*****************************************************************************
* FUNCTION
* ByteCounter
* DESCRIPTION
*
* PARAMETERS
* ptr [?]
* flag [IN]
* size [IN]
* RETURNS
* void
*****************************************************************************/
void ByteCounter(void *ptr, int flag, int size) /* -1 free, +1 alloc */
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
goslMemCount += (long)(size * flag);
if (MaxDynamicMemUsed < goslMemCount)
{
MaxDynamicMemUsed = goslMemCount;
}
return;
}
/*-------------------------------------------------------------------
Function Name : OslMallocCHK
Description : This function allocates memory and maintain the
link list info of file name and line number
Input : no of bytes
file name
line number
Output : void pointer
-------------------------------------------------------------------*/
/*****************************************************************************
* FUNCTION
* OslMallocCHK
* DESCRIPTION
*
* PARAMETERS
* nob [IN]
* fileName [?]
* lineNumber [IN]
* RETURNS
* void
*****************************************************************************/
void *OslMallocCHK(S32 nob, char *fileName, int lineNumber, ...)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
void *ptr = NULL;
U8 j, i;
S32 nob1; /* =nob; */
void *ptrAct;
U16 maskingByte;
OSLMEMALLOC *memData;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (MallocFirstTime)
{
OslIntMemoryStart();
MallocFirstTime = 0;
}
if (!nob)
{
return NULL;
}
if (nob < 8)
{
nob = 8;
}
nob1 = nob;
maskingByte = 1;
i = 0;
for (j = 0; j < 16; j++)
{
if (nob1 & maskingByte)
{
i++;
}
if (!(nob1 & 0xfffe))
{
break;
}
nob1 >>= 1;
}
if (i > 1)
{
nob1 = 1;
nob1 <<= ++j;
}
else
{
nob1 = nob;
}
bufferCount[j - 3]++;
#ifdef MMI_ON_WIN32
ptrAct = (void*)malloc(nob1);
#else
ptrAct = (void*)get_ctrl_buffer(nob1);
#endif
if (memoryListCount < MEMORY_LIST_LENGTH)
{
for (j = 0; memoryList[j].isAllocated; j++);
memData = &memoryList[j];
memoryListCount++;
for (j = strlen(fileName); j > 1; j--)
{
if (fileName[j - 1] == '\\')
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -