home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / vopl / glvopl.lha / glvopl / src / mem.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-04-24  |  749 b   |  47 lines

  1. #include "vopl.h"
  2.  
  3. /*
  4.  * newm1
  5.  *
  6.  *    allocate a one dimensional array
  7.  */
  8. float *
  9. newm1(n)
  10.     int    n;
  11. {
  12.     float    *p;
  13.  
  14.     if ((p = (float *)malloc(sizeof(float) * n)) == (float *)NULL) {
  15.         fprintf(stderr, "newm1: request for %d bytes returns NULL\n", n);
  16.         exit(1);
  17.     }
  18.  
  19.     return(p);
  20. }
  21.  
  22. /*
  23.  * newm2
  24.  *
  25.  *    allocate an array of arrays
  26.  */
  27. float **
  28. newm2(m, n)
  29.     int m, n;
  30. {
  31.     float  **mat;
  32.     int i;
  33.  
  34.     if ((mat = (float **)malloc((unsigned)sizeof(float *) * m)) == (float **)NULL) {
  35.         fprintf(stderr, "newm2: request for %d bytes returns NULL\n", n);
  36.         exit(1);
  37.     }
  38.  
  39.     for (i = 0; i < m; i++)
  40.         if ((mat[i] = (float *)malloc(n * sizeof(float))) == (float *)NULL) {
  41.             fprintf(stderr, "newm2: request for %d bytes returns NULL\n", n);
  42.             exit(1);
  43.         }
  44.  
  45.     return(mat);
  46. }
  47.