libcm is a C development framework with an emphasis on audio signal processing applications.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cmLinkedHeap.h 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #ifndef cmLinkedHeap_h
  2. #define cmLinkedHeap_h
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. //( { file_desc:"Implements a block based memory heap manager." kw:[base]}
  7. //
  8. // There are two advantages to using this memory manager over the cmMallocDebug
  9. // manager. It alleviates memory fragmentation by pre-allocating large blocks of memory
  10. // which are then used to fullfill many small memory requests. Second it can
  11. // act as a garbage collector by releasing all the memory it is managing at once.
  12. // This can reduce code complexity by eliminating for a class instance to release internally
  13. // allocated objects.
  14. //)
  15. //(
  16. typedef cmHandle_t cmLHeapH_t;
  17. extern cmLHeapH_t cmLHeapNullHandle;
  18. cmLHeapH_t cmLHeapCreate( unsigned dfltBlockByteCnt, cmCtx_t* ctx );
  19. void cmLHeapDestroy( cmLHeapH_t* hp );
  20. void* cmLHeapAllocate( cmLHeapH_t h, void* orgDataPtr, unsigned eleCnt, unsigned eleByteCnt, unsigned flags, const char* fileStr, const char* funcStr, unsigned fileLine );
  21. cmChar_t* cmLHeapAllocStr( cmLHeapH_t h, void* orgDataPtr, const cmChar_t* str, unsigned charCnt, unsigned flags, const char* fileStr, const char* funcStr, unsigned fileLine );
  22. // If ptr==NULL the function returns with no side effect.
  23. void cmLHeapFree( cmLHeapH_t h, void* ptr );
  24. void cmLHeapFreeDebug( cmLHeapH_t h, void* dataPtr, const char* fileName, const char* funcName, unsigned fileLine );
  25. // If *ptr==NULL the function returns with no side effect.
  26. void cmLHeapFreePtr( cmLHeapH_t h, void** ptrPtr );
  27. void cmLHeapFreePtrDebug( cmLHeapH_t h, void** dataPtrPtr, const char* fileName, const char* funcName, unsigned fileLine );
  28. bool cmLHeapIsValid( cmLHeapH_t h );
  29. // Return the values set in call to cmLHeapCreate()
  30. unsigned cmLHeapDefaultBlockByteCount( cmLHeapH_t h );
  31. unsigned cmLHeapGuardByteCount( cmLHeapH_t h );
  32. unsigned cmLHeapAlignByteCount( cmLHeapH_t h );
  33. unsigned cmLHeapInitializeFlags( cmLHeapH_t h );
  34. // If releaseFl==false then marks all internal memory blocks as empty but does not actually
  35. // release the associated memory, otherwise releases all memory blocks.
  36. void cmLHeapClear( cmLHeapH_t h, bool releaseFl );
  37. // Return true if 'ptr' points into a linked heap block.
  38. bool cmLHeapIsPtrInHeap( cmLHeapH_t h, const void* ptr );
  39. // mmFlags take the same values as the flags parameter to cmMmReport().
  40. cmMmRC_t cmLHeapReportErrors( cmLHeapH_t h, unsigned mmFlags );
  41. void cmLHeapReport( cmLHeapH_t h );
  42. void cmLHeapTest();
  43. #if cmDEBUG_FL == 0
  44. #define cmLHeapAlloc( h, byteCnt ) cmLHeapAllocate(h,NULL,1,byteCnt, kAlignMmFl, NULL,NULL,0)
  45. #define cmLHeapAllocZ(h, byteCnt ) cmLHeapAllocate(h,NULL,1,byteCnt, kAlignMmFl | kZeroMmFl, NULL,NULL,0)
  46. #define cmLhAlloc(h,t,n) ((t*)cmLHeapAllocate(h,NULL,n,sizeof(t), kAlignMmFl, NULL,NULL,0))
  47. #define cmLhAllocZ(h,t,n) ((t*)cmLHeapAllocate(h,NULL,n,sizeof(t), kAlignMmFl | kZeroMmFl, NULL,NULL,0))
  48. #define cmLhResizeN( h,t,p,n) ((t*)cmLHeapAllocate(h,p, n,sizeof(t), kAlignMmFl, NULL,NULL,0))
  49. #define cmLhResizeNZ(h,t,p,n) ((t*)cmLHeapAllocate(h,p, n,sizeof(t), kAlignMmFl | kZeroMmFl, NULL,NULL,0))
  50. #define cmLhAllocStr( h, str ) cmLHeapAllocStr( h, NULL, str, cmStringLen(str), kAlignMmFl, NULL,NULL,0 )
  51. #define cmLhAllocStrN( h, str, n ) cmLHeapAllocStr( h, NULL, str, n, kAlignMmFl, NULL,NULL,0 )
  52. #define cmLhResizeStr( h, p, str ) cmLHeapAllocStr( h, p, str, cmStringLen(str), kAlignMmFl, NULL,NULL,0 )
  53. #define cmLhResizeStrN( h, p, str, n ) cmLHeapAllocStr( h, p, str, n, kAlignMmFl, NULL,NULL,0 )
  54. #define cmLhFree( h, p ) cmLHeapFree( h, p )
  55. #define cmLhFreePtr(h, p ) cmLHeapFreePtr( h, p )
  56. #else
  57. #define cmLHeapAlloc( h, byteCnt ) cmLHeapAllocate(h,NULL,1,byteCnt, kAlignMmFl, __FILE__,__FUNCTION__,__LINE__)
  58. #define cmLHeapAllocZ(h, byteCnt ) cmLHeapAllocate(h,NULL,1,byteCnt, kAlignMmFl | kZeroMmFl, __FILE__,__FUNCTION__,__LINE__)
  59. #define cmLhAlloc(h,t,n) ((t*)cmLHeapAllocate(h,NULL,n,sizeof(t), kAlignMmFl, __FILE__,__FUNCTION__,__LINE__))
  60. #define cmLhAllocZ(h,t,n) ((t*)cmLHeapAllocate(h,NULL,n,sizeof(t), kAlignMmFl | kZeroMmFl, __FILE__,__FUNCTION__,__LINE__))
  61. #define cmLhResizeN( h,t,p,n) ((t*)cmLHeapAllocate(h,p, n,sizeof(t), kAlignMmFl, __FILE__,__FUNCTION__,__LINE__))
  62. #define cmLhResizeNZ(h,t,p,n) ((t*)cmLHeapAllocate(h,p, n,sizeof(t), kAlignMmFl | kZeroMmFl, __FILE__,__FUNCTION__,__LINE__))
  63. #define cmLhAllocStr( h, str ) cmLHeapAllocStr( h, NULL, str, cmStringLen(str), kAlignMmFl, __FILE__,__FUNCTION__,__LINE__ )
  64. #define cmLhAllocStrN( h, str, n ) cmLHeapAllocStr( h, NULL, str, n, kAlignMmFl, __FILE__,__FUNCTION__,__LINE__ )
  65. #define cmLhResizeStr( h, p, str ) cmLHeapAllocStr( h, p, str, cmStringLen(str), kAlignMmFl, __FILE__,__FUNCTION__,__LINE__ )
  66. #define cmLhResizeStrN( h, p, str, n ) cmLHeapAllocStr( h, p, str, n, kAlignMmFl, __FILE__,__FUNCTION__,__LINE__ )
  67. #define cmLhFree( h, p ) cmLHeapFreeDebug( h, p, __FILE__,__FUNCTION__,__LINE__ )
  68. #define cmLhFreePtr(h, p ) cmLHeapFreePtrDebug( h, p, __FILE__,__FUNCTION__,__LINE__ )
  69. #endif
  70. //)
  71. #ifdef __cplusplus
  72. }
  73. #endif
  74. #endif