pmemory.h

00001 /*---------------------------------------------------------------------------*
00002  *  pmemory.h  *
00003  *                                                                           *
00004  *  Copyright 2007 Nuance Communciations, Inc.                               *
00005  *                                                                           *
00006  *  Licensed under the Apache License, Version 2.0 (the 'License');          *
00007  *  you may not use this file except in compliance with the License.         *
00008  *                                                                           *
00009  *  You may obtain a copy of the License at                                  *
00010  *      http://www.apache.org/licenses/LICENSE-2.0                           *
00011  *                                                                           *
00012  *  Unless required by applicable law or agreed to in writing, software      *
00013  *  distributed under the License is distributed on an 'AS IS' BASIS,        *
00014  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 
00015  *  See the License for the specific language governing permissions and      *
00016  *  limitations under the License.                                           *
00017  *                                                                           *
00018  *---------------------------------------------------------------------------*/
00019 
00020 #ifndef PMEMORY_H
00021 #define PMEMORY_H
00022 
00023 
00024 
00025 #define PMEM_MAP_TRACE
00026 
00027 #include "PortPrefix.h"
00028 #include "ptypes.h"
00029 #include "pstdio.h"
00030 #include <stddef.h>
00031 #include <stdlib.h>
00032 
00044 #define _VAL(x) #x
00045 
00048 #define _STR(x) _VAL(x)
00049 
00050 #ifdef DISABLE_MALLOC
00051 #define malloc #error
00052 #define calloc #error
00053 #define realloc #error
00054 #define free #error
00055 #endif
00056 
00057 #ifndef offsetof
00058 #define offsetof(type, member) ((size_t) &(((type *)0)->member))
00059 #endif
00060 
00061 /*
00062  * PMEM_MAP_TRACE is not defined by default.
00063  * It is up to user to define PMEM_MAP_TRACE;
00064  * define in either makefile or here for test purpose.
00065  */
00066 
00070 #define STATIC_CAST(self, subClass, member) ((subClass*) (((char*) self) - (offsetof(subClass, member))))
00071 
00072 #ifdef PMEM_MAP_TRACE
00073 
00076 #define MALLOC(nbBytes, tag) (pmalloc(nbBytes, tag, L(__FILE__), __LINE__))
00077 #else
00078 
00081 #define MALLOC(nbBytes, tag) (pmalloc(nbBytes))
00082 #endif
00083 
00084 #ifdef PMEM_MAP_TRACE
00085 
00088 #define CALLOC(nbElem, elemSize, tag) (pcalloc(nbElem,  elemSize  , tag, L(__FILE__), __LINE__))
00089 #define CALLOC_CLR(nbElem, elemSize, tag) (pcalloc(nbElem,  elemSize  , tag, L(__FILE__), __LINE__))
00090 #else
00091 
00094 #define CALLOC(nbElem, elemSize, tag) (pcalloc(nbElem,  elemSize))
00095 #define CALLOC_CLR(nbElem, elemSize, tag) (pcalloc(nbElem,  elemSize))
00096 #endif
00097 
00098 #ifdef PMEM_MAP_TRACE
00099 
00102 #define REALLOC(ptr, newSize) (prealloc(ptr, newSize, L(__FILE__), __LINE__))
00103 #else
00104 
00107 #define REALLOC(ptr, newSize) (prealloc(ptr, newSize))
00108 #endif
00109 
00113 #define NEW(type, tag) ((type*) MALLOC(sizeof(type), tag))
00114 
00118 #define NEW_ARRAY(type, nbElem, tag) ((type *) CALLOC(nbElem, sizeof(type), tag))
00119 
00120 #ifdef PMEM_MAP_TRACE
00121 
00124 #define FREE(ptr) pfree(ptr, L(__FILE__), __LINE__)
00125 #else
00126 
00129 #define FREE(ptr) pfree(ptr)
00130 #endif
00131 
00150 #ifdef PMEM_MAP_TRACE
00151 PORTABLE_API void *pmalloc(size_t nbBytes, const LCHAR* tag, const LCHAR* file, int line);
00152 #else
00153 PORTABLE_API void *pmalloc(size_t nbBytes);
00154 #endif
00155 
00172 #ifdef PMEM_MAP_TRACE
00173 PORTABLE_API void *pcalloc(size_t nbItems, size_t itemSize, const LCHAR* tag, const LCHAR* file, int line);
00174 #else
00175 PORTABLE_API void *pcalloc(size_t nbItems, size_t itemSize);
00176 #endif
00177 
00192 #ifdef PMEM_MAP_TRACE
00193 PORTABLE_API void *prealloc(void* ptr, size_t newSize, const LCHAR* file, int line);
00194 #else
00195 PORTABLE_API void *prealloc(void* ptr, size_t newSize);
00196 #endif
00197 
00210 #ifdef PMEM_MAP_TRACE
00211 PORTABLE_API void pfree(void* ptr, const LCHAR* file, int line);
00212 #else
00213 PORTABLE_API void pfree(void* ptr);
00214 #endif
00215 
00229 PORTABLE_API ESR_ReturnCode PMemInit(void);
00230 
00237 PORTABLE_API ESR_ReturnCode PMemShutdown(void);
00238 
00247 PORTABLE_API ESR_ReturnCode PMemSetLogFile(PFile* file);
00248 
00254 PORTABLE_API ESR_ReturnCode PMemDumpLogFile(void);
00255 
00264 PORTABLE_API ESR_ReturnCode PMemSetLogEnabled(ESR_BOOL value);
00265 
00274 PORTABLE_API ESR_ReturnCode PMemLogFree(void* ptr);
00275 
00285 PORTABLE_API ESR_ReturnCode PMemReport(PFile* file);
00286 
00295 PORTABLE_API ESR_ReturnCode PMemorySetPoolSize(size_t size);
00296 
00303 PORTABLE_API ESR_ReturnCode PMemoryGetPoolSize(size_t *size);
00304 
00309 #endif

Generated on Thu May 1 15:37:25 2008 for SREC by  doxygen 1.5.3