home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vectoper.zip / RTShmOps.cpp < prev    next >
C/C++ Source or Header  |  1996-09-19  |  2KB  |  91 lines

  1.  
  2.  
  3. #include <stdio.h>
  4. #include <assert.h>
  5.  
  6. #include "RTTypes.h"
  7. #include "RTObjOps.h"
  8. #include "RTIMOps.h"
  9. #include "RayTrace.h"
  10.  
  11.  
  12. char * Sh_malloc(unsigned size);
  13. char * Sh_calloc(unsigned  elem_count,  unsigned size);
  14.  
  15.  
  16.  
  17.  
  18. /*
  19.  *******************************************************************************
  20.  *
  21.  *  Name:  Sh_calloc
  22.  *
  23.  *  Purpose:  this routine allocates space for an array of "elem_count" elements
  24.  *            where each element contains "size" bytes.  The heap used for
  25.  *            allocation is setup in the calypso shared memory segment.
  26.  *
  27.  *
  28.  *
  29.  *  Input Parameters
  30.  *
  31.  *     elem_count -    number of elements to be allocated
  32.  *     size - byte count of each element
  33.  *
  34.  *
  35.  *  Output Parameters
  36.  *
  37.  *     none
  38.  *
  39.  *******************************************************************************
  40.  */
  41. char *
  42.    Sh_calloc(unsigned  elem_count,  unsigned size)
  43.       {
  44.        char * chunk_ptr;
  45.  
  46.        chunk_ptr = Sh_malloc( (unsigned) (elem_count * size) );
  47.        return(chunk_ptr);
  48.       }
  49.  
  50.  
  51.  
  52.  
  53. /*
  54.  *******************************************************************************
  55.  *
  56.  *  Name:  Sh_malloc
  57.  *
  58.  *  Purpose:  this routine returns a pointer to a block of "size"bytes.  The
  59.  *            heap used for allocation is setup in the calypso shared memory
  60.  *            segment.
  61.  *
  62.  *
  63.  *
  64.  *  Input Parameters
  65.  *
  66.  *     size - number of bytes to be allocated
  67.  *
  68.  *
  69.  *  Output Parameters
  70.  *
  71.  *     none
  72.  *
  73.  *******************************************************************************
  74.  */
  75. char *
  76.    Sh_malloc(unsigned size)
  77.       {
  78.        char *chunk_ptr;
  79.  
  80.        assert( (shared->Sh_Heap.allocated_space+size) < FREE_SPACE_LIMIT);
  81.        shared->Sh_Heap.allocated_space += size;
  82.  
  83.        chunk_ptr = shared->Sh_Heap.free_space_ptr;
  84.        shared->Sh_Heap.free_space_ptr += size;
  85.  
  86.        assert(shared->Sh_Heap.free_space_ptr <
  87.                                   ((char *) &shared->Sh_Heap.end_of_free_space));
  88.  
  89.        return(chunk_ptr);
  90.       }
  91.