home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sa104os2.zip / SATHR104.ZIP / SATHER / SYSTEM / GC / INCLUDE / GC_TYPED.H < prev    next >
C/C++ Source or Header  |  1995-01-09  |  3KB  |  86 lines

  1. /* 
  2.  * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
  3.  * Copyright (c) 1991-1994 by Xerox Corporation.  All rights reserved.
  4.  *
  5.  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
  6.  * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
  7.  *
  8.  * Permission is hereby granted to use or copy this program
  9.  * for any purpose,  provided the above notices are retained on all copies.
  10.  * Permission to modify the code and to distribute modified code is granted,
  11.  * provided the above notices are retained, and a notice that the code was
  12.  * modified is included with the above copyright notice.
  13.  */
  14. /*
  15.  * Some simple primitives for allocation with explicit type information.
  16.  * Facilities for dynamic type inference may be added later.
  17.  * Should be used only for extremely performance critical applications,
  18.  * or if conservative collector leakage is otherwise a problem (unlikely).
  19.  * Note that this is implemented completely separately from the rest
  20.  * of the collector, and is not linked in unless referenced.
  21.  */
  22. /* Boehm, May 19, 1994 2:13 pm PDT */
  23.  
  24. #ifndef _GC_TYPED_H
  25. # define _GC_TYPED_H
  26. # ifndef _GC_H
  27. #   include "gc.h"
  28. # endif
  29.  
  30. typedef GC_word * GC_bitmap;
  31.     /* The least significant bit of the first word is one if    */
  32.     /* the first word in the object may be a pointer.        */
  33.     
  34. # define GC_get_bit(bm, index) \
  35.         (((bm)[divWORDSZ(index)] >> modWORDSZ(index)) & 1)
  36. # define GC_set_bit(bm, index) \
  37.         (bm)[divWORDSZ(index)] |= (word)1 << modWORDSZ(index)
  38.  
  39. typedef GC_word GC_descr;
  40.  
  41. #if defined(__STDC__) || defined(__cplusplus)
  42.   extern GC_descr GC_make_descriptor(GC_bitmap bm, size_t len);
  43. #else
  44.   extern GC_descr GC_make_descriptor(/* GC_bitmap bm, size_t len */);
  45. #endif
  46.         /* Return a type descriptor for the object whose layout    */
  47.         /* is described by the argument.            */
  48.         /* The least significant bit of the first word is one    */
  49.         /* if the first word in the object may be a pointer.    */
  50.         /* The second argument specifies the number of        */
  51.         /* meaningful bits in the bitmap.  The actual object     */
  52.         /* may be larger (but not smaller).  Any additional    */
  53.         /* words in the object are assumed not to contain     */
  54.         /* pointers.                        */
  55.         /* Returns a conservative approximation in the        */
  56.         /* (unlikely) case of insufficient memory to build    */
  57.         /* the descriptor.  Calls to GC_make_descriptor        */
  58.         /* may consume some amount of a finite resource.  This    */
  59.         /* is intended to be called once per type, not once    */
  60.         /* per allocation.                    */
  61.  
  62. #if defined(__STDC__) || defined(__cplusplus)
  63.   extern void * GC_malloc_explicitly_typed(size_t size_in_bytes, GC_descr d);
  64. #else
  65.   extern char * GC_malloc_explicitly_typed(/* size_in_bytes, descriptor */);
  66. #endif
  67.         /* Allocate an object whose layout is described by d.    */
  68.         /* The resulting object MAY NOT BE PASSED TO REALLOC.    */
  69.         
  70. #if defined(__STDC__) || defined(__cplusplus)
  71.   extern void * GC_calloc_explicitly_typed(size_t nelements,
  72.                          size_t element_size_in_bytes,
  73.                          GC_descr d);
  74. #else
  75.   char * GC_calloc_explicitly_typed(/* nelements, size_in_bytes, descriptor */);
  76.       /* Allocate an array of nelements elements, each of the    */
  77.       /* given size, and with the given descriptor.        */
  78.       /* The elemnt size must be a multiple of the byte    */
  79.       /* alignment required for pointers.  E.g. on a 32-bit    */
  80.       /* machine with 16-bit aligned pointers, size_in_bytes    */
  81.       /* must be a multiple of 2.                */
  82. #endif
  83.  
  84. #endif /* _GC_TYPED_H */
  85.  
  86.