home *** CD-ROM | disk | FTP | other *** search
/ C/C++ User's Journal & Wi…eveloper's Journal Tools / C-C__Users_Journal_and_Windows_Developers_Journal_Tools_1997.iso / windbase / windbase.exe / MEMSLC.3 / ARRAY / MDARRAY.C next >
C/C++ Source or Header  |  1995-10-28  |  6KB  |  126 lines

  1. /*****************************************************************************\
  2. **                                                                           **
  3. **  WW     WW IIIIIIII NNN   NN DDDDDDD  BBBBBBB     AA     SSSSSS EEEEEEEE  **
  4. **  WW  W  WW    II    NNNN  NN DD    DD BB    BB  AA  AA  SS      EE        **
  5. **  WW  W  WW    II    NN NN NN DD    DD BBBBBBB  AAAAAAAA  SSSSSS EEEEEE    **
  6. **   WW W WW     II    NN  NNNN DD    DD BB    BB AA    AA      SS EE        **
  7. **    WWWWW   IIIIIIII NN   NNN DDDDDDD  BBBBBBB  AA    AA SSSSSS  EEEEEEEE  **
  8. **                                                                           **
  9. **   SSSSSS  OOOOOO  FFFFFFFF TTTTTTTT WW     WW    AA    RRRRRRR  EEEEEEEE  **
  10. **  SS      OO    OO FF          TT    WW  W  WW  AA  AA  RR    RR EE        **
  11. **   SSSSS  OO    OO FFFFF       TT    WW  W  WW AAAAAAAA RRRRRRR  EEEEEE    **
  12. **       SS OO    OO FF          TT     WW W WW  AA    AA RR   RR  EE        **
  13. **  SSSSSS   OOOOOO  FF          TT      WWWWW   AA    AA RR    RR EEEEEEEE  **
  14. **                                                                           **
  15. *********** NOTICE ************************************************************
  16. **        This file contains valuable trade secrets and proprietary          **
  17. **        assets of Windbase Software Inc.  Embodying substantial            **
  18. **        creative efforts and confidential information.  Unauthorized       **
  19. **        use, copying, decompiling, translating, disclosure or              **
  20. **        transfer, of any kind, is strictly prohibited.                     **
  21. **                                                                           **
  22. **        COPYRIGHT (C) 1992, 1993, 1994.  Windbase Software Inc.            **
  23. **        ALL RIGHTS RESERVED.                                               **
  24. \*****************************************************************************/
  25.  
  26. /*************************************************************************\
  27. **** Array Demo **********************************************************
  28. **
  29. **  This is an example of using the MemSL array allocator.  Arrays
  30. **  of any size and dimension can be dynamically allocated during
  31. **  runtime.  To allocate an array simply call WBArrayOpen().  To
  32. **  free the array call WBArrayClose().  To access the array call
  33. **  WBArrayArray(), this will return a pointer to the array
  34. **  allocated.  You will notice that for each dimension in the array
  35. **  you have to define the '*', so for a two dimensional array you
  36. **  will need '**array' just like the 'argv' command line argument,
  37. **  likewise you will need to define '**********Array' for a ten
  38. **  dimensional array.  The WBArray allocates memory across segments
  39. **  on MS-DOS machines and therefore you have access to all the
  40. **  available memory of your system.
  41. **
  42. \*************************************************************************/
  43.  
  44. #include <stdio.h>
  45. #ifdef HAS_UNISTD_H
  46. #  include <unistd.h>
  47. #else
  48. #  include <stdlib.h>
  49. #endif
  50.  
  51. #include "../../memsl.h"
  52.  
  53. #ifdef WBSTDC
  54.   int main(void)
  55. #else
  56.   int main()
  57. #endif
  58.   {
  59.     WBARRAY *array;         /* Array structure used for tracking the */
  60.                             /* dimensions, sizes and memory returned */
  61.                             /* during the open call.                 */
  62.     char **********strarray;     /* Ten dimensional character array. */
  63.     int i1, i2, i3, i4, i5, i6, i7, i8, i9; /* Temporary integers used */
  64.                                             /* to set and print the    */
  65.                                             /* elements of the array.  */
  66.  
  67.       /*
  68.       ** WBArrayOpen() allocates the memory for the array and
  69.       ** returns a pointer to a WBARRAY structure which contains
  70.       ** the array and the information used to allocate and
  71.       ** deallocate the array.
  72.       */
  73.  
  74. #if defined(WBMEMTRACE) || defined(WBUSERMEM)
  75.     if (getenv("WBOVRCHK") || getenv("WBMEMCHK"))
  76.       {
  77.         printf("This program will run extremely slow with the WBOVRCHK\n");
  78.         printf("and WBMEMCHK environment variables set.  Please unset\n");
  79.         printf("these environment variables.\n\n");
  80.         exit(1);
  81.       }
  82. #endif
  83.  
  84.     if ((array = WBArrayOpen(NULL,"2,2,2,2,2,2,2,2,2,40")) != NULL)
  85.       {
  86.           /*
  87.           ** WBArrayArray() simply returns the array.  The return
  88.           ** value should be assigned to a variable capable of
  89.           ** accessing each dimension.  At this point we can use the
  90.           ** array as though it were a predefined array.
  91.           */
  92.         strarray = WBArrayArray(array);
  93.         for (i1 = 0; i1 < 2; i1++)
  94.           for (i2 = 0; i2 < 2; i2++)
  95.             for (i3 = 0; i3 < 2; i3++)
  96.               for (i4 = 0; i4 < 2; i4++)
  97.                 for (i5 = 0; i5 < 2; i5++)
  98.                   for (i6 = 0; i6 < 2; i6++)
  99.                     for (i7 = 0; i7 < 2; i7++)
  100.                       for (i8 = 0; i8 < 2; i8++)
  101.                         for (i9 = 0; i9 < 2; i9++)
  102.                           sprintf(strarray[i1][i2][i3][i4][i5][i6][i7][i8][i9],
  103.                           "10 dimensional array %d%d%d%d%d%d%d%d%d",
  104.                           i1,i2,i3,i4,i5,i6,i7,i8,i9);
  105.         for (i1 = 0; i1 < 2; i1++)
  106.           for (i2 = 0; i2 < 2; i2++)
  107.             for (i3 = 0; i3 < 2; i3++)
  108.               for (i4 = 0; i4 < 2; i4++)
  109.                 for (i5 = 0; i5 < 2; i5++)
  110.                   for (i6 = 0; i6 < 2; i6++)
  111.                     for (i7 = 0; i7 < 2; i7++)
  112.                       for (i8 = 0; i8 < 2; i8++)
  113.                         for (i9 = 0; i9 < 2; i9++)
  114.                           printf("%s\n",strarray[i1][i2][i3][i4][i5][i6][i7][i8][i9]);
  115.           /*
  116.           ** Once we are through with the array we need to deallocate
  117.           ** the array.  Notice we do not free the 'strarray'
  118.           ** variable, this is because the array belongs to the
  119.           ** WBARRAY structure.
  120.           */
  121.         WBArrayClose(array);
  122.       }
  123.     exit(0);
  124.     return(0);
  125.   }
  126.