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
00039
00040
00041 #define RT_MH_DONTKEEPFREE 0x1
00042 #define RT_MH_VALIDATEPTR 0x2
00043 #define RT_MH_CHECKHEAP 0x4
00044
00045 #define OSRTMH_PROPID_DEFBLKSIZE 1
00046 #define OSRTMH_PROPID_SETFLAGS 2
00047 #define OSRTMH_PROPID_CLEARFLAGS 3
00048 #define OSRTMH_PROPID_KEEPFREEUNITS 4
00049
00050 #define OSRTMH_PROPID_USER 10
00051
00052 #define OSRTXM_K_MEMBLKSIZ (4*1024)
00053
00067 #define OSRTALLOCTYPE(pctxt,type) \
00068 (type*) rtxMemHeapAlloc (&(pctxt)->pMemHeap, sizeof(type))
00069
00076 #define OSRTALLOCTYPEZ(pctxt,type) \
00077 (type*) rtxMemHeapAllocZ (&(pctxt)->pMemHeap, sizeof(type))
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 #define OSRTREALLOCARRAY(pctxt,pseqof,type) do {\
00091 if (sizeof(type)*(pseqof)->n < (pseqof)->n) return RTERR_NOMEM; \
00092 if (((pseqof)->elem = (type*) rtxMemHeapRealloc \
00093 (&(pctxt)->pMemHeap, (pseqof)->elem, sizeof(type)*(pseqof)->n)) == 0) \
00094 return RTERR_NOMEM; \
00095 } while (0)
00096
00097 #ifndef _NO_MALLOC
00098 #define OSCRTMALLOC0(nbytes) malloc(nbytes)
00099 #define OSCRTFREE0(ptr) free(ptr)
00100 #else
00101
00102 #ifdef _NO_THREADS
00103 extern EXTERNRT OSCTXT g_ctxt;
00104
00105 #define OSCRTMALLOC0(nbytes) rtxMemAlloc(&g_ctxt,(nbytes))
00106 #define OSCRTFREE0(ptr) rtxMemFreePtr(&g_ctxt,(ptr))
00107 #else
00108 #define OSCRTMALLOC0(nbytes) (void*)0
00109 #define OSCRTFREE0(ptr) (void*)0
00110
00111 #endif
00112 #endif
00113
00114 #define OSCRTMALLOC rtxMemAlloc
00115 #define OSCRTFREE rtxMemFreePtr
00116
00117 struct OSRTDList;
00118
00119 #ifdef __cplusplus
00120 extern "C" {
00121 #endif
00122
00123
00124
00125
00126 #if !defined(OSCDECL)
00127 #if defined(_MSC_VER) || defined(__BORLANDC__)
00128 #define OSCDECL __cdecl
00129 #else
00130 #define OSCDECL
00131 #endif
00132 #endif
00133
00134
00135
00136
00137 typedef void *(OSCDECL *OSMallocFunc ) (size_t size);
00138 typedef void *(OSCDECL *OSReallocFunc) (void *ptr, size_t size);
00139 typedef void (OSCDECL *OSFreeFunc ) (void *ptr);
00140
00141 EXTERNRT void rtxMemHeapAddRef (void** ppvMemHeap);
00142 EXTERNRT void* rtxMemHeapAlloc (void** ppvMemHeap, size_t nbytes);
00143 EXTERNRT void* rtxMemHeapAllocZ (void** ppvMemHeap, size_t nbytes);
00144 EXTERNRT int rtxMemHeapCheckPtr (void** ppvMemHeap, const void* mem_p);
00145 EXTERNRT int rtxMemHeapCreate (void** ppvMemHeap);
00146
00147 EXTERNRT int rtxMemHeapCreateExt (void** ppvMemHeap,
00148 OSMallocFunc malloc_func,
00149 OSReallocFunc realloc_func,
00150 OSFreeFunc free_func);
00151
00152 EXTERNRT void rtxMemHeapFreeAll (void** ppvMemHeap);
00153 EXTERNRT void rtxMemHeapFreePtr (void** ppvMemHeap, void* mem_p);
00154 EXTERNRT void* rtxMemHeapMarkSaved (void** ppvMemHeap,
00155 const void* mem_p,
00156 OSBOOL saved);
00157 EXTERNRT void* rtxMemHeapRealloc (void** ppvMemHeap,
00158 void* mem_p, size_t nbytes_);
00159 EXTERNRT void rtxMemHeapRelease (void** ppvMemHeap);
00160 EXTERNRT void rtxMemHeapReset (void** ppvMemHeap);
00161 EXTERNRT void rtxMemHeapSetProperty (void** ppvMemHeap,
00162 OSUINT32 propId, void* pProp);
00163
00164 EXTERNRT void* rtxMemNewArray (size_t nbytes);
00165 EXTERNRT void* rtxMemNewArrayZ (size_t nbytes);
00166 EXTERNRT void rtxMemDeleteArray (void* mem_p);
00167
00168 EXTERNRT void* rtxMemHeapAutoPtrRef (void** ppvMemHeap, void* ptr);
00169 EXTERNRT int rtxMemHeapAutoPtrUnref (void** ppvMemHeap, void* ptr);
00170 EXTERNRT int rtxMemHeapAutoPtrGetRefCount (void** ppvMemHeap, void* mem_p);
00171
00172 EXTERNRT void rtxMemHeapInvalidPtrHook (void** ppvMemHeap, const void* mem_p);
00173
00174 EXTERNRT void rtxMemHeapCheck (void** ppvMemHeap, const char* file, int line);
00175 EXTERNRT void rtxMemHeapPrint (void** ppvMemHeap);
00176
00177 #if !defined(_ARMTCC) && !defined(__SYMBIAN32__)
00178
00193 #ifndef _RT_ALLOC_FUNC_WITH_CONTEXT
00194
00195 EXTERNRT void rtxMemSetAllocFuncs (OSMallocFunc malloc_func,
00196 OSReallocFunc realloc_func,
00197 OSFreeFunc free_func);
00198
00199 #else
00200
00201 EXTERNRT void rtxMemSetAllocCtxtFuncs (OSMallocCtxtFunc malloc_func,
00202 OSReallocCtxtFunc realloc_func,
00203 OSFreeCtxtFunc free_func);
00204
00205 #endif
00206 #endif
00207
00208 EXTERNRT void rtxMemFreeOpenSeqExt
00209 (OSCTXT* pctxt, struct OSRTDList *pElemList);
00210
00211
00212
00213
00214
00215
00216
00217 EXTERNRT OSUINT32 rtxMemHeapGetDefBlkSize (OSCTXT* pctxt);
00218
00219 #ifndef __SYMBIAN32__
00220
00227 EXTERNRT void rtxMemSetDefBlkSize (OSUINT32 blkSize);
00228 #endif
00229
00236 EXTERNRT OSUINT32 rtxMemGetDefBlkSize ();
00237
00246 EXTERNRT OSBOOL rtxMemIsZero (const void* pmem, size_t memsiz);
00247
00248 #ifdef _STATIC_HEAP
00249 EXTERNRT void rtxMemSetStaticBuf (void* memHeapBuf, OSUINT32 blkSize);
00250 #endif
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261 #define rtxMemAlloc(pctxt,nbytes) \
00262 rtxMemHeapAlloc(&(pctxt)->pMemHeap,nbytes)
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273 #define rtxMemAllocZ(pctxt,nbytes) \
00274 rtxMemHeapAllocZ(&(pctxt)->pMemHeap,nbytes)
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290 #define rtxMemRealloc(pctxt,mem_p,nbytes) \
00291 rtxMemHeapRealloc(&(pctxt)->pMemHeap, (void*)mem_p, nbytes)
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304 #define rtxMemFreePtr(pctxt,mem_p) \
00305 rtxMemHeapFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315 #define rtxMemFree(pctxt) \
00316 rtxMemHeapFreeAll(&(pctxt)->pMemHeap)
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332 #define rtxMemReset(pctxt) \
00333 rtxMemHeapReset(&(pctxt)->pMemHeap)
00334
00344 #define rtxMemAllocType(pctxt,ctype) \
00345 (ctype*)rtxMemHeapAlloc(&(pctxt)->pMemHeap,sizeof(ctype))
00346
00356 #define rtxMemAllocTypeZ(pctxt,ctype) \
00357 (ctype*)rtxMemHeapAllocZ(&(pctxt)->pMemHeap,sizeof(ctype))
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370 #define rtxMemFreeType(pctxt,mem_p) \
00371 rtxMemHeapFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
00372
00382 #define rtxMemAllocArray(pctxt,n,type) \
00383 (type*)rtxMemHeapAlloc (&(pctxt)->pMemHeap, sizeof(type)*n)
00384
00385 #define rtxMemAllocArrayZ(pctxt,n,type) \
00386 (type*)rtxMemHeapAllocZ (&(pctxt)->pMemHeap, sizeof(type)*n)
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399 #define rtxMemFreeArray(pctxt,mem_p) \
00400 rtxMemHeapFreePtr(&(pctxt)->pMemHeap, (void*)mem_p)
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416 #define rtxMemReallocArray(pctxt,mem_p,n,type) \
00417 (type*)rtxMemHeapRealloc(&(pctxt)->pMemHeap, (void*)mem_p, sizeof(type)*n)
00418
00419
00432 #define rtxMemNewAutoPtr(pctxt,nbytes) \
00433 rtxMemHeapAlloc(&(pctxt)->pMemHeap, nbytes)
00434
00443 #define rtxMemAutoPtrRef(pctxt,ptr) \
00444 rtxMemHeapAutoPtrRef(&(pctxt)->pMemHeap, (void*)(ptr))
00445
00456 #define rtxMemAutoPtrUnref(pctxt,ptr) \
00457 rtxMemHeapAutoPtrUnref(&(pctxt)->pMemHeap, (void*)(ptr))
00458
00467 #define rtxMemAutoPtrGetRefCount(pctxt,ptr) \
00468 rtxMemHeapAutoPtrGetRefCount(&(pctxt)->pMemHeap, (void*)(ptr))
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478 #define rtxMemCheckPtr(pctxt,mem_p) \
00479 rtxMemHeapCheckPtr(&(pctxt)->pMemHeap, (void*)mem_p)
00480
00481
00482
00483
00484
00485
00486 #define rtxMemCheck(pctxt) \
00487 rtxMemHeapCheck(&(pctxt)->pMemHeap, __FILE__, __LINE__)
00488
00489
00490
00491
00492
00493
00494 #define rtxMemPrint(pctxt) \
00495 rtxMemHeapPrint(&(pctxt)->pMemHeap)
00496
00497
00498
00499
00500
00501
00502
00503
00504 #define rtxMemSetProperty(pctxt,propId,pProp) \
00505 rtxMemHeapSetProperty (&(pctxt)->pMemHeap, propId, pProp)
00506
00507
00508 #ifdef __cplusplus
00509 }
00510 #endif
00511
00514 #endif