home *** CD-ROM | disk | FTP | other *** search
/ IRIS Development Option 6.2 / IRIS_Development_Option_6.2_814-0478-001.iso / dist / c_dev.idb / usr / share / src / customalloc / UserMalloc.h.z / UserMalloc.h
C/C++ Source or Header  |  1996-03-14  |  1KB  |  77 lines

  1. /* -*-c-*- */
  2. #ifndef _UserMalloc_h_
  3. #define _UserMalloc_h_
  4.  
  5. #ifndef _UserMalloc_pre_h_
  6. #  include "UserMalloc-pre.h"
  7. #endif
  8.  
  9. #ifndef SIZE_SZ
  10. #  define SIZE_SZ                   (sizeof(SizeType))
  11. #endif
  12.  
  13. #ifndef MINSIZE
  14. #  define MINSIZE              16 /* from malloc.c */
  15. #endif
  16.  
  17. /*
  18.  * Return the malloc_chunk structure from a value returned by malloc
  19.  */
  20.  
  21. static MallocChunk *external_to_malloc(SizeType *v)
  22. {
  23.   return( (MallocChunk*) &v[-1]) ;
  24. }
  25.  
  26. /*
  27.  * The other way around
  28.  */
  29. static SizeType *malloc_to_external(MallocChunk *p)
  30. {
  31.   SizeType *v = (SizeType*) p;
  32.   return( &v[1]);
  33. }
  34.  
  35. static int malloc_size(MallocChunk *p)
  36. {
  37.   return ( (p -> size) & ~0x1 );
  38. }
  39.  
  40. /*****************************************************************************/
  41.  
  42.  
  43. #ifndef CUSTOMALLOC_CACHE_BITS
  44. #  define CUSTOMALLOC_CACHE_BITS    (5)
  45. #endif
  46.  
  47. #define CUSTOMALLOC_CACHE_VALUE    (1 << CUSTOMALLOC_CACHE_BITS)
  48. #define CUSTOMALLOC_CACHE_MASK    (~(CUSTOMALLOC_CACHE_VALUE - 1 ))
  49.  
  50. #ifdef _IN_OUTPUT_
  51. static void *__customalloc_unlink(char **list)
  52. {
  53.   char **p = (char **) *list;
  54.   *list = p[0];
  55.   return( &p[0] );
  56. }
  57.  
  58. static void __customalloc_link(char **list, void *ptr)
  59. {
  60.   char **p = (char **) ptr;
  61.   p[0] = *list;
  62.   *list = (char *) ptr;
  63. }
  64. #endif
  65.  
  66. static int size_external_to_internal (int size)
  67. {
  68.   return( (size + CUSTOMALLOC_CACHE_VALUE - 1) & CUSTOMALLOC_CACHE_MASK );
  69. }
  70.  
  71. static int size_malloc_to_internal (int size)
  72. {
  73.   return( size & CUSTOMALLOC_CACHE_MASK );
  74. }
  75.  
  76. #endif
  77.