00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00028 #ifndef __RTXMEMORY_H__
00029 #define __RTXMEMORY_H__
00030
00031 #include "rtxsrc/rtxContext.h"
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #define RT_MH_DONTKEEPFREE 0x1
00042 #define RT_MH_VALIDATEPTR 0x2
00043 #define RT_MH_CHECKHEAP 0x4
00044 #define RT_MH_TRACE 0x8
00045 #define RT_MH_DIAG 0x10
00046 #define RT_MH_DIAG_DEBUG 0x20
00047 #define RT_MH_ZEROONFREE 0x40
00048
00049 #define OSRTMH_PROPID_DEFBLKSIZE 1
00050 #define OSRTMH_PROPID_SETFLAGS 2
00051 #define OSRTMH_PROPID_CLEARFLAGS 3
00052 #define OSRTMH_PROPID_KEEPFREEUNITS 4
00053
00054 #define OSRTMH_PROPID_USER 10
00055
00056 #define OSRTXM_K_MEMBLKSIZ (4*1024)
00057
00071 #define OSRTALLOCTYPE(pctxt,type) \
00072 (type*) rtxMemHeapAlloc (&(pctxt)->pMemHeap, sizeof(type))
00073
00080 #define OSRTALLOCTYPEZ(pctxt,type) \
00081 (type*) rtxMemHeapAllocZ (&(pctxt)->pMemHeap, sizeof(type))
00082
00094 #define OSRTREALLOCARRAY(pctxt,pseqof,type) do {\
00095 if (sizeof(type)*(pseqof)->n < (pseqof)->n) return RTERR_NOMEM; \
00096 if (((pseqof)->elem = (type*) rtxMemHeapRealloc \
00097 (&(pctxt)->pMemHeap, (pseqof)->elem, sizeof(type)*(pseqof)->n)) == 0) \
00098 return RTERR_NOMEM; \
00099 } while (0)
00100
00101 #ifndef _NO_MALLOC
00102 #define OSCRTMALLOC0(nbytes) malloc(nbytes)
00103 #define OSCRTFREE0(ptr) free(ptr)
00104 #else
00105
00106 #ifdef _NO_THREADS
00107 extern EXTERNRT OSCTXT g_ctxt;
00108
00109 #define OSCRTMALLOC0(nbytes) rtxMemAlloc(&g_ctxt,(nbytes))
00110 #define OSCRTFREE0(ptr) rtxMemFreePtr(&g_ctxt,(ptr))
00111 #else
00112 #define OSCRTMALLOC0(nbytes) (void*)0
00113 #define OSCRTFREE0(ptr) (void*)0
00114
00115 #endif
00116 #endif
00117
00118 #define OSCRTMALLOC rtxMemAlloc
00119 #define OSCRTFREE rtxMemFreePtr
00120
00121 struct OSRTDList;
00122
00123 #ifdef __cplusplus
00124 extern "C" {
00125 #endif
00126
00127
00128
00129
00130 #if !defined(OSCDECL)
00131 #if defined(_MSC_VER) || defined(__BORLANDC__)
00132 #define OSCDECL __cdecl
00133 #else
00134 #define OSCDECL
00135 #endif
00136 #endif
00137
00138 EXTERNRT void rtxMemHeapAddRef (void** ppvMemHeap);
00139 EXTERNRT void* rtxMemHeapAlloc (void** ppvMemHeap, size_t nbytes);
00140 EXTERNRT void* rtxMemHeapAllocZ (void** ppvMemHeap, size_t nbytes);
00141 EXTERNRT void* rtxMemHeapSysAlloc (void** ppvMemHeap, size_t nbytes);
00142 EXTERNRT int rtxMemHeapCheckPtr (void** ppvMemHeap, const void* mem_p);
00143 EXTERNRT int rtxMemHeapCreate (void** ppvMemHeap);
00144
00145 EXTERNRT int rtxMemHeapCreateExt (void** ppvMemHeap,
00146 OSMallocFunc malloc_func,
00147 OSReallocFunc realloc_func,
00148 OSFreeFunc free_func);
00149
00150 EXTERNRT void rtxMemHeapFreeAll (void** ppvMemHeap);
00151 EXTERNRT void rtxMemHeapFreePtr (void** ppvMemHeap, void* mem_p);
00152 EXTERNRT void rtxMemHeapSysFreePtr (void** ppvMemHeap, void* mem_p);
00153
00154 EXTERNRT void* rtxMemHeapRealloc
00155 (void** ppvMemHeap, void* mem_p, size_t nbytes_);
00156
00157 EXTERNRT void* rtxMemHeapSysRealloc
00158 (void** ppvMemHeap, void* mem_p, size_t nbytes_);
00159
00160 EXTERNRT void rtxMemHeapRelease (void** ppvMemHeap);
00161 EXTERNRT void rtxMemHeapReset (void** ppvMemHeap);
00162 EXTERNRT void rtxMemHeapSetProperty (void** ppvMemHeap,
00163 OSUINT32 propId, void* pProp);
00164
00165 EXTERNRT void* rtxMemNewArray (size_t nbytes);
00166 EXTERNRT void* rtxMemNewArrayZ (size_t nbytes);
00167 EXTERNRT void rtxMemDeleteArray (void* mem_p);
00168
00169 EXTERNRT void* rtxMemHeapAutoPtrRef (void** ppvMemHeap, void* ptr);
00170 EXTERNRT int rtxMemHeapAutoPtrUnref (void** ppvMemHeap, void* ptr);
00171 EXTERNRT int rtxMemHeapAutoPtrGetRefCount (void** ppvMemHeap, void* mem_p);
00172
00173 EXTERNRT void rtxMemHeapInvalidPtrHook (void** ppvMemHeap, const void* mem_p);
00174
00175 EXTERNRT void rtxMemHeapCheck (void** ppvMemHeap, const char* file, int line);
00176 EXTERNRT void rtxMemHeapPrint (void** ppvMemHeap);
00177
00178 #if !defined(_ARMTCC) && !defined(__SYMBIAN32__)
00179
00194 EXTERNRT void rtxMemSetAllocFuncs (OSMallocFunc malloc_func,
00195 OSReallocFunc realloc_func,
00196 OSFreeFunc free_func);
00197
00198 #endif
00199
00200 EXTERNRT void rtxMemFreeOpenSeqExt
00201 (OSCTXT* pctxt, struct OSRTDList *pElemList);
00202
00209 EXTERNRT OSUINT32 rtxMemHeapGetDefBlkSize (OSCTXT* pctxt);
00210
00211 #ifndef __SYMBIAN32__
00212
00219 EXTERNRT void rtxMemSetDefBlkSize (OSUINT32 blkSize);
00220 #endif
00221
00228 EXTERNRT OSUINT32 rtxMemGetDefBlkSize ();
00229
00237 EXTERNRT OSBOOL rtxMemHeapIsEmpty (OSCTXT* pctxt);
00238
00247 EXTERNRT OSBOOL rtxMemIsZero (const void* pmem, size_t memsiz);
00248
00249 #ifdef _STATIC_HEAP
00250 EXTERNRT void rtxMemSetStaticBuf (void* memHeapBuf, OSUINT32 blkSize);
00251 #endif
00252
00262 #define rtxMemAlloc(pctxt,nbytes) \
00263 rtxMemHeapAlloc(&(pctxt)->pMemHeap,nbytes)
00264
00275 #define rtxMemSysAlloc(pctxt,nbytes) \
00276 rtxMemHeapSysAlloc(&(pctxt)->pMemHeap,nbytes)
00277
00287 #define rtxMemAllocZ(pctxt,nbytes) \
00288 rtxMemHeapAllocZ(&(pctxt)->pMemHeap,nbytes)
00289
00304 #define rtxMemRealloc(pctxt,mem_p,nbytes) \
00305 rtxMemHeapRealloc(&(pctxt)->pMemHeap, (void*)mem_p, nbytes)
00306
00323 #define rtxMemSysRealloc(pctxt,mem_p,nbytes) \
00324 rtxMemHeapSysRealloc(&(pctxt)->pMemHeap,(void*)mem_p,nbytes)
00325
00337 #define rtxMemFreePtr(pctxt,mem_p) \
00338 rtxMemHeapFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
00339
00350 #define rtxMemSysFreePtr(pctxt,mem_p) \
00351 rtxMemHeapSysFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
00352
00361 #define rtxMemFree(pctxt) \
00362 rtxMemHeapFreeAll(&(pctxt)->pMemHeap)
00363
00378 #define rtxMemReset(pctxt) \
00379 rtxMemHeapReset(&(pctxt)->pMemHeap)
00380
00390 #define rtxMemAllocType(pctxt,ctype) \
00391 (ctype*)rtxMemHeapAlloc(&(pctxt)->pMemHeap,sizeof(ctype))
00392
00402 #define rtxMemAllocTypeZ(pctxt,ctype) \
00403 (ctype*)rtxMemHeapAllocZ(&(pctxt)->pMemHeap,sizeof(ctype))
00404
00416 #define rtxMemFreeType(pctxt,mem_p) \
00417 rtxMemHeapFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
00418
00428 #define rtxMemAllocArray(pctxt,n,type) \
00429 (type*)rtxMemHeapAlloc (&(pctxt)->pMemHeap, sizeof(type)*n)
00430
00440 #define rtxMemAllocArrayZ(pctxt,n,type) \
00441 (type*)rtxMemHeapAllocZ (&(pctxt)->pMemHeap, sizeof(type)*n)
00442
00454 #define rtxMemFreeArray(pctxt,mem_p) \
00455 rtxMemHeapFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
00456
00471 #define rtxMemReallocArray(pctxt,mem_p,n,type) \
00472 (type*)rtxMemHeapRealloc(&(pctxt)->pMemHeap, (void*)mem_p, sizeof(type)*n)
00473
00474
00487 #define rtxMemNewAutoPtr(pctxt,nbytes) \
00488 rtxMemHeapAlloc(&(pctxt)->pMemHeap, nbytes)
00489
00498 #define rtxMemAutoPtrRef(pctxt,ptr) \
00499 rtxMemHeapAutoPtrRef(&(pctxt)->pMemHeap, (void*)(ptr))
00500
00511 #define rtxMemAutoPtrUnref(pctxt,ptr) \
00512 rtxMemHeapAutoPtrUnref(&(pctxt)->pMemHeap, (void*)(ptr))
00513
00522 #define rtxMemAutoPtrGetRefCount(pctxt,ptr) \
00523 rtxMemHeapAutoPtrGetRefCount(&(pctxt)->pMemHeap, (void*)(ptr))
00524
00533 #define rtxMemCheckPtr(pctxt,mem_p) \
00534 rtxMemHeapCheckPtr(&(pctxt)->pMemHeap, (void*)mem_p)
00535
00541 #define rtxMemCheck(pctxt) \
00542 rtxMemHeapCheck(&(pctxt)->pMemHeap, __FILE__, __LINE__)
00543
00549 #define rtxMemPrint(pctxt) \
00550 rtxMemHeapPrint(&(pctxt)->pMemHeap)
00551
00559 #define rtxMemSetProperty(pctxt,propId,pProp) \
00560 rtxMemHeapSetProperty (&(pctxt)->pMemHeap, propId, pProp)
00561
00562
00563 #ifdef __cplusplus
00564 }
00565 #endif
00566
00569 #endif