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 void* rtxMemHeapSysAllocZ (void** ppvMemHeap, size_t nbytes);
00143 EXTERNRT int rtxMemHeapCheckPtr (void** ppvMemHeap, const void* mem_p);
00144 EXTERNRT int rtxMemHeapCreate (void** ppvMemHeap);
00145
00146 EXTERNRT int rtxMemHeapCreateExt (void** ppvMemHeap,
00147 OSMallocFunc malloc_func,
00148 OSReallocFunc realloc_func,
00149 OSFreeFunc free_func);
00150
00151 EXTERNRT void rtxMemHeapFreeAll (void** ppvMemHeap);
00152 EXTERNRT void rtxMemHeapFreePtr (void** ppvMemHeap, void* mem_p);
00153 EXTERNRT void rtxMemHeapSysFreePtr (void** ppvMemHeap, void* mem_p);
00154
00155 EXTERNRT void* rtxMemHeapRealloc
00156 (void** ppvMemHeap, void* mem_p, size_t nbytes_);
00157
00158 EXTERNRT void* rtxMemHeapSysRealloc
00159 (void** ppvMemHeap, void* mem_p, size_t nbytes_);
00160
00161 EXTERNRT void rtxMemHeapRelease (void** ppvMemHeap);
00162 EXTERNRT void rtxMemHeapReset (void** ppvMemHeap);
00163 EXTERNRT void rtxMemHeapSetProperty (void** ppvMemHeap,
00164 OSUINT32 propId, void* pProp);
00165
00166 EXTERNRT void* rtxMemNewArray (size_t nbytes);
00167 EXTERNRT void* rtxMemNewArrayZ (size_t nbytes);
00168 EXTERNRT void rtxMemDeleteArray (void* mem_p);
00169
00170 EXTERNRT void* rtxMemHeapAutoPtrRef (void** ppvMemHeap, void* ptr);
00171 EXTERNRT int rtxMemHeapAutoPtrUnref (void** ppvMemHeap, void* ptr);
00172 EXTERNRT int rtxMemHeapAutoPtrGetRefCount (void** ppvMemHeap, void* mem_p);
00173
00174 EXTERNRT void rtxMemHeapInvalidPtrHook (void** ppvMemHeap, const void* mem_p);
00175
00176 EXTERNRT void rtxMemHeapCheck (void **ppvMemHeap, const char* file, int line);
00177 EXTERNRT void rtxMemHeapPrint (void **ppvMemHeap);
00178
00179 #if !defined(_ARMTCC) && !defined(__SYMBIAN32__)
00180
00195 EXTERNRT void rtxMemSetAllocFuncs (OSMallocFunc malloc_func,
00196 OSReallocFunc realloc_func,
00197 OSFreeFunc free_func);
00198
00199 #endif
00200
00201 EXTERNRT void rtxMemFreeOpenSeqExt
00202 (OSCTXT* pctxt, struct OSRTDList *pElemList);
00203
00210 EXTERNRT OSUINT32 rtxMemHeapGetDefBlkSize (OSCTXT* pctxt);
00211
00212 #ifndef __SYMBIAN32__
00213
00220 EXTERNRT void rtxMemSetDefBlkSize (OSUINT32 blkSize);
00221 #endif
00222
00229 EXTERNRT OSUINT32 rtxMemGetDefBlkSize ();
00230
00238 EXTERNRT OSBOOL rtxMemHeapIsEmpty (OSCTXT* pctxt);
00239
00248 EXTERNRT OSBOOL rtxMemIsZero (const void* pmem, size_t memsiz);
00249
00250 #ifdef _STATIC_HEAP
00251 EXTERNRT void rtxMemSetStaticBuf (void* memHeapBuf, OSUINT32 blkSize);
00252 #endif
00253
00263 #define rtxMemAlloc(pctxt,nbytes) \
00264 rtxMemHeapAlloc(&(pctxt)->pMemHeap,nbytes)
00265
00276 #define rtxMemSysAlloc(pctxt,nbytes) \
00277 rtxMemHeapSysAlloc(&(pctxt)->pMemHeap,nbytes)
00278
00288 #define rtxMemAllocZ(pctxt,nbytes) \
00289 rtxMemHeapAllocZ(&(pctxt)->pMemHeap,nbytes)
00290
00304 #define rtxMemSysAllocZ(pctxt,nbytes) \
00305 rtxMemHeapSysAllocZ(&(pctxt)->pMemHeap,nbytes)
00306
00307
00322 #define rtxMemRealloc(pctxt,mem_p,nbytes) \
00323 rtxMemHeapRealloc(&(pctxt)->pMemHeap, (void*)mem_p, nbytes)
00324
00341 #define rtxMemSysRealloc(pctxt,mem_p,nbytes) \
00342 rtxMemHeapSysRealloc(&(pctxt)->pMemHeap,(void*)mem_p,nbytes)
00343
00355 #define rtxMemFreePtr(pctxt,mem_p) \
00356 rtxMemHeapFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
00357
00368 #define rtxMemSysFreePtr(pctxt,mem_p) \
00369 rtxMemHeapSysFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
00370
00379 EXTERNRT void rtxMemFree (OSCTXT* pctxt);
00380
00395 EXTERNRT void rtxMemReset (OSCTXT* pctxt);
00396
00406 #define rtxMemAllocType(pctxt,ctype) \
00407 (ctype*)rtxMemHeapAlloc(&(pctxt)->pMemHeap,sizeof(ctype))
00408
00422 #define rtxMemSysAllocType(pctxt,ctype) \
00423 (ctype*)rtxMemHeapSysAlloc(&(pctxt)->pMemHeap,sizeof(ctype))
00424
00434 #define rtxMemAllocTypeZ(pctxt,ctype) \
00435 (ctype*)rtxMemHeapAllocZ(&(pctxt)->pMemHeap,sizeof(ctype))
00436
00450 #define rtxMemSysAllocTypeZ(pctxt,ctype) \
00451 (ctype*)rtxMemHeapSysAllocZ(&(pctxt)->pMemHeap,sizeof(ctype))
00452
00464 #define rtxMemFreeType(pctxt,mem_p) \
00465 rtxMemHeapFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
00466
00478 #define rtxMemSysFreeType(pctxt,mem_p) \
00479 rtxMemHeapSysFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
00480
00490 #define rtxMemAllocArray(pctxt,n,type) \
00491 (type*)rtxMemHeapAlloc (&(pctxt)->pMemHeap, sizeof(type)*n)
00492
00506 #define rtxMemSysAllocArray(pctxt,n,type) \
00507 (type*)rtxMemHeapSysAlloc (&(pctxt)->pMemHeap, sizeof(type)*n)
00508
00518 #define rtxMemAllocArrayZ(pctxt,n,type) \
00519 (type*)rtxMemHeapAllocZ (&(pctxt)->pMemHeap, sizeof(type)*n)
00520
00532 #define rtxMemFreeArray(pctxt,mem_p) \
00533 rtxMemHeapFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
00534
00546 #define rtxMemSysFreeArray(pctxt,mem_p) \
00547 rtxMemHeapSysFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
00548
00563 #define rtxMemReallocArray(pctxt,mem_p,n,type) \
00564 (type*)rtxMemHeapRealloc(&(pctxt)->pMemHeap, (void*)mem_p, sizeof(type)*n)
00565
00566
00579 #define rtxMemNewAutoPtr(pctxt,nbytes) \
00580 rtxMemHeapAlloc(&(pctxt)->pMemHeap, nbytes)
00581
00590 #define rtxMemAutoPtrRef(pctxt,ptr) \
00591 rtxMemHeapAutoPtrRef(&(pctxt)->pMemHeap, (void*)(ptr))
00592
00603 #define rtxMemAutoPtrUnref(pctxt,ptr) \
00604 rtxMemHeapAutoPtrUnref(&(pctxt)->pMemHeap, (void*)(ptr))
00605
00614 #define rtxMemAutoPtrGetRefCount(pctxt,ptr) \
00615 rtxMemHeapAutoPtrGetRefCount(&(pctxt)->pMemHeap, (void*)(ptr))
00616
00625 #define rtxMemCheckPtr(pctxt,mem_p) \
00626 rtxMemHeapCheckPtr(&(pctxt)->pMemHeap, (void*)mem_p)
00627
00633 #define rtxMemCheck(pctxt) \
00634 rtxMemHeapCheck(&(pctxt)->pMemHeap, __FILE__, __LINE__)
00635
00641 #define rtxMemPrint(pctxt) \
00642 rtxMemHeapPrint(&(pctxt)->pMemHeap)
00643
00651 #define rtxMemSetProperty(pctxt,propId,pProp) \
00652 rtxMemHeapSetProperty (&(pctxt)->pMemHeap, propId, pProp)
00653
00654
00655 #ifdef __cplusplus
00656 }
00657 #endif
00658
00661 #endif