background image
<< Freeing Unallocated Memory | Using the Memory Profiling Viewer >>
<< Freeing Unallocated Memory | Using the Memory Profiling Viewer >>

the standard ANSI functions

Runtime Analysis
/* ret now contains the actual-pointer */
/* Here is any user code making ret a reallocated pointer to a
heap or
simulated heap memory block of actual_size bytes */
...
/* After comes second Memory Profiling action */
return _PurifyLTHeapAction ( _PurifyLT_API_ALLOC, ret, size, 0
);
/* The user-pointer is returned */
}
To free memory without using the delay:
void my_free ( int partId, void * ptr )
{
/* Memory Profiling action comes first */
void *ret = _PurifyLTHeapAction ( _PurifyLT_API_FREE, ptr, 0, 0
);
/* Any code insuring actual deallocation of ret */
}
To free memory using a delay:
void my_free ( int partId, void * ptr )
{
/* Memory Profiling action comes first */
void *ret = _PurifyLTHeapAction ( _PurifyLT_API_FREE, ptr, 0, 1
);
/* Nothing to do here */
}
To obtain the user size of a block:
size_t my_msize ( int partId, void * ptr )
{
return _PurifyLTHeapPtrSize ( ptr );
}
Use the following macros to save customization time when dealing with functions
that have the same prototypes as the standard ANSI functions:
#define _PurifyLT_MALLOC_LIKE(func) \
void *RTRT_CONCAT_MACRO(usr_,func) ( RTRT_SIZE_T size ) \
{ \
void *ret; \
ret = func ( _PurifyLTHeapActualSize ( size ) ); \
return _PurifyLTHeapAction ( _PurifyLT_API_ALLOC, ret, size, 0
); \
}
#define _PurifyLT_CALLOC_LIKE(func) \
void *RTRT_CONCAT_MACRO(usr_,func) ( RTRT_SIZE_T nelem,
RTRT_SIZE_T elsize ) \
{ \
void *ret; \
ret = func ( _PurifyLTHeapActualSize ( nelem * elsize ) ); \
return _PurifyLTHeapAction ( _PurifyLT_API_ALLOC, ret, nelem *
elsize, 0 ); \
}
#define _PurifyLT_REALLOC_LIKE(func,delayed_free) \
void *RTRT_CONCAT_MACRO(usr_,func) ( void *ptr, RTRT_SIZE_T size
75