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 #define RT_MH_ZEROARRAY 0x80
00049 #define RT_MH_SYSALLOC 0x100
00050
00051 #define OSRTMH_PROPID_DEFBLKSIZE 1
00052 #define OSRTMH_PROPID_SETFLAGS 2
00053 #define OSRTMH_PROPID_CLEARFLAGS 3
00054 #define OSRTMH_PROPID_KEEPFREEUNITS 4
00055
00056 #define OSRTMH_PROPID_USER 10
00057
00058 #define OSRTXM_K_MEMBLKSIZ (4*1024)
00059
00073 #define OSRTALLOCTYPE(pctxt,type) \
00074 (type*) rtxMemHeapAlloc (&(pctxt)->pMemHeap, sizeof(type))
00075
00082 #define OSRTALLOCTYPEZ(pctxt,type) \
00083 (type*) rtxMemHeapAllocZ (&(pctxt)->pMemHeap, sizeof(type))
00084
00096 #define OSRTREALLOCARRAY(pctxt,pseqof,type) do {\
00097 if (sizeof(type)*(pseqof)->n < (pseqof)->n) return RTERR_NOMEM; \
00098 if (((pseqof)->elem = (type*) rtxMemHeapRealloc \
00099 (&(pctxt)->pMemHeap, (pseqof)->elem, sizeof(type)*(pseqof)->n)) == 0) \
00100 return RTERR_NOMEM; \
00101 } while (0)
00102
00103 #ifndef _NO_MALLOC
00104 #define OSCRTMALLOC0(nbytes) malloc(nbytes)
00105 #define OSCRTFREE0(ptr) free(ptr)
00106 #else
00107
00108 #ifdef _NO_THREADS
00109 extern EXTERNRT OSCTXT g_ctxt;
00110
00111 #define OSCRTMALLOC0(nbytes) rtxMemAlloc(&g_ctxt,(nbytes))
00112 #define OSCRTFREE0(ptr) rtxMemFreePtr(&g_ctxt,(ptr))
00113 #else
00114 #define OSCRTMALLOC0(nbytes) (void*)0
00115 #define OSCRTFREE0(ptr) (void*)0
00116
00117 #endif
00118 #endif
00119
00120 #define OSCRTMALLOC rtxMemAlloc
00121 #define OSCRTFREE rtxMemFreePtr
00122
00123 struct OSRTDList;
00124
00125 #ifdef __cplusplus
00126 extern "C" {
00127 #endif
00128
00129
00130
00131
00132 #if !defined(OSCDECL)
00133 #if defined(_MSC_VER) || defined(__BORLANDC__)
00134 #define OSCDECL __cdecl
00135 #else
00136 #define OSCDECL
00137 #endif
00138 #endif
00139
00140 EXTERNRT void rtxMemHeapAddRef (void** ppvMemHeap);
00141 EXTERNRT void* rtxMemHeapAlloc (void** ppvMemHeap, size_t nbytes);
00142 EXTERNRT void* rtxMemHeapAllocZ (void** ppvMemHeap, size_t nbytes);
00143 EXTERNRT void* rtxMemHeapSysAlloc (void** ppvMemHeap, size_t nbytes);
00144 EXTERNRT void* rtxMemHeapSysAllocZ (void** ppvMemHeap, size_t nbytes);
00145 EXTERNRT int rtxMemHeapCheckPtr (void** ppvMemHeap, const void* mem_p);
00146 EXTERNRT int rtxMemHeapCreate (void** ppvMemHeap);
00147
00148 EXTERNRT int rtxMemHeapCreateExt (void** ppvMemHeap,
00149 OSMallocFunc malloc_func,
00150 OSReallocFunc realloc_func,
00151 OSFreeFunc free_func);
00152
00153 EXTERNRT void rtxMemHeapFreeAll (void** ppvMemHeap);
00154 EXTERNRT void rtxMemHeapFreePtr (void** ppvMemHeap, void* mem_p);
00155 EXTERNRT void rtxMemHeapSysFreePtr (void** ppvMemHeap, void* mem_p);
00156
00157 EXTERNRT void* rtxMemHeapRealloc
00158 (void** ppvMemHeap, void* mem_p, size_t nbytes_);
00159
00160 EXTERNRT void* rtxMemHeapSysRealloc
00161 (void** ppvMemHeap, void* mem_p, size_t nbytes_);
00162
00163 EXTERNRT void rtxMemHeapRelease (void** ppvMemHeap);
00164 EXTERNRT void rtxMemHeapReset (void** ppvMemHeap);
00165 EXTERNRT void rtxMemHeapSetProperty (void** ppvMemHeap,
00166 OSUINT32 propId, void* pProp);
00167
00168 EXTERNRT void* rtxMemNewArray (size_t nbytes);
00169 EXTERNRT void* rtxMemNewArrayZ (size_t nbytes);
00170 EXTERNRT void rtxMemDeleteArray (void* mem_p);
00171
00172 EXTERNRT void* rtxMemHeapAutoPtrRef (void** ppvMemHeap, void* ptr);
00173 EXTERNRT int rtxMemHeapAutoPtrUnref (void** ppvMemHeap, void* ptr);
00174 EXTERNRT int rtxMemHeapAutoPtrGetRefCount (void** ppvMemHeap, void* mem_p);
00175
00176 EXTERNRT void rtxMemHeapInvalidPtrHook (void** ppvMemHeap, const void* mem_p);
00177
00178 EXTERNRT void rtxMemHeapCheck (void **ppvMemHeap, const char* file, int line);
00179 EXTERNRT void rtxMemHeapPrint (void **ppvMemHeap);
00180
00181 #if !defined(_ARMTCC) && !defined(__SYMBIAN32__)
00182
00197 EXTERNRT void rtxMemSetAllocFuncs (OSMallocFunc malloc_func,
00198 OSReallocFunc realloc_func,
00199 OSFreeFunc free_func);
00200
00201 #endif
00202
00203 EXTERNRT void rtxMemFreeOpenSeqExt
00204 (OSCTXT* pctxt, struct OSRTDList *pElemList);
00205
00212 EXTERNRT OSUINT32 rtxMemHeapGetDefBlkSize (OSCTXT* pctxt);
00213
00214 #ifndef __SYMBIAN32__
00215
00222 EXTERNRT void rtxMemSetDefBlkSize (OSUINT32 blkSize);
00223 #endif
00224
00231 EXTERNRT OSUINT32 rtxMemGetDefBlkSize (OSVOIDARG);
00232
00240 EXTERNRT OSBOOL rtxMemHeapIsEmpty (OSCTXT* pctxt);
00241
00250 EXTERNRT OSBOOL rtxMemIsZero (const void* pmem, size_t memsiz);
00251
00252 #ifdef _STATIC_HEAP
00253 EXTERNRT void rtxMemSetStaticBuf (void* memHeapBuf, OSUINT32 blkSize);
00254 #endif
00255
00265 #define rtxMemAlloc(pctxt,nbytes) \
00266 rtxMemHeapAlloc(&(pctxt)->pMemHeap,nbytes)
00267
00278 #define rtxMemSysAlloc(pctxt,nbytes) \
00279 rtxMemHeapSysAlloc(&(pctxt)->pMemHeap,nbytes)
00280
00290 #define rtxMemAllocZ(pctxt,nbytes) \
00291 rtxMemHeapAllocZ(&(pctxt)->pMemHeap,nbytes)
00292
00306 #define rtxMemSysAllocZ(pctxt,nbytes) \
00307 rtxMemHeapSysAllocZ(&(pctxt)->pMemHeap,nbytes)
00308
00309
00324 #define rtxMemRealloc(pctxt,mem_p,nbytes) \
00325 rtxMemHeapRealloc(&(pctxt)->pMemHeap, (void*)mem_p, nbytes)
00326
00343 #define rtxMemSysRealloc(pctxt,mem_p,nbytes) \
00344 rtxMemHeapSysRealloc(&(pctxt)->pMemHeap,(void*)mem_p,nbytes)
00345
00357 #define rtxMemFreePtr(pctxt,mem_p) \
00358 rtxMemHeapFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
00359
00370 #define rtxMemSysFreePtr(pctxt,mem_p) \
00371 rtxMemHeapSysFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
00372
00381 EXTERNRT void rtxMemFree (OSCTXT* pctxt);
00382
00397 EXTERNRT void rtxMemReset (OSCTXT* pctxt);
00398
00408 #define rtxMemAllocType(pctxt,ctype) \
00409 (ctype*)rtxMemHeapAlloc(&(pctxt)->pMemHeap,sizeof(ctype))
00410
00424 #define rtxMemSysAllocType(pctxt,ctype) \
00425 (ctype*)rtxMemHeapSysAlloc(&(pctxt)->pMemHeap,sizeof(ctype))
00426
00436 #define rtxMemAllocTypeZ(pctxt,ctype) \
00437 (ctype*)rtxMemHeapAllocZ(&(pctxt)->pMemHeap,sizeof(ctype))
00438
00452 #define rtxMemSysAllocTypeZ(pctxt,ctype) \
00453 (ctype*)rtxMemHeapSysAllocZ(&(pctxt)->pMemHeap,sizeof(ctype))
00454
00466 #define rtxMemFreeType(pctxt,mem_p) \
00467 rtxMemHeapFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
00468
00480 #define rtxMemSysFreeType(pctxt,mem_p) \
00481 rtxMemHeapSysFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
00482
00492 #define rtxMemAllocArray(pctxt,n,type) \
00493 (type*)rtxMemAllocArray2 (pctxt, n, sizeof(type), 0)
00494
00495 EXTERNRT void* rtxMemAllocArray2
00496 (OSCTXT* pctxt, OSSIZE numElements, OSSIZE typeSize, OSUINT32 flags);
00497
00511 #define rtxMemSysAllocArray(pctxt,n,type) \
00512 (type*)rtxMemAllocArray2 (pctxt, n, sizeof(type), RT_MH_SYSALLOC)
00513
00523 #define rtxMemAllocArrayZ(pctxt,n,type) \
00524 (type*)rtxMemAllocArray2 (pctxt, n, sizeof(type), RT_MH_ZEROARRAY)
00525
00537 #define rtxMemFreeArray(pctxt,mem_p) \
00538 rtxMemHeapFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
00539
00551 #define rtxMemSysFreeArray(pctxt,mem_p) \
00552 rtxMemHeapSysFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
00553
00568 #define rtxMemReallocArray(pctxt,mem_p,n,type) \
00569 (type*)rtxMemHeapRealloc(&(pctxt)->pMemHeap, (void*)mem_p, sizeof(type)*n)
00570
00571
00584 #define rtxMemNewAutoPtr(pctxt,nbytes) \
00585 rtxMemHeapAlloc(&(pctxt)->pMemHeap, nbytes)
00586
00595 #define rtxMemAutoPtrRef(pctxt,ptr) \
00596 rtxMemHeapAutoPtrRef(&(pctxt)->pMemHeap, (void*)(ptr))
00597
00608 #define rtxMemAutoPtrUnref(pctxt,ptr) \
00609 rtxMemHeapAutoPtrUnref(&(pctxt)->pMemHeap, (void*)(ptr))
00610
00619 #define rtxMemAutoPtrGetRefCount(pctxt,ptr) \
00620 rtxMemHeapAutoPtrGetRefCount(&(pctxt)->pMemHeap, (void*)(ptr))
00621
00630 #define rtxMemCheckPtr(pctxt,mem_p) \
00631 rtxMemHeapCheckPtr(&(pctxt)->pMemHeap, (void*)mem_p)
00632
00638 #define rtxMemCheck(pctxt) \
00639 rtxMemHeapCheck(&(pctxt)->pMemHeap, __FILE__, __LINE__)
00640
00646 #define rtxMemPrint(pctxt) \
00647 rtxMemHeapPrint(&(pctxt)->pMemHeap)
00648
00656 #define rtxMemSetProperty(pctxt,propId,pProp) \
00657 rtxMemHeapSetProperty (&(pctxt)->pMemHeap, propId, pProp)
00658
00659
00660 #ifdef __cplusplus
00661 }
00662 #endif
00663
00666 #endif