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 >
Wrap
C/C++ Source or Header
|
1995-10-28
|
6KB
|
126 lines
/*****************************************************************************\
** **
** WW WW IIIIIIII NNN NN DDDDDDD BBBBBBB AA SSSSSS EEEEEEEE **
** WW W WW II NNNN NN DD DD BB BB AA AA SS EE **
** WW W WW II NN NN NN DD DD BBBBBBB AAAAAAAA SSSSSS EEEEEE **
** WW W WW II NN NNNN DD DD BB BB AA AA SS EE **
** WWWWW IIIIIIII NN NNN DDDDDDD BBBBBBB AA AA SSSSSS EEEEEEEE **
** **
** SSSSSS OOOOOO FFFFFFFF TTTTTTTT WW WW AA RRRRRRR EEEEEEEE **
** SS OO OO FF TT WW W WW AA AA RR RR EE **
** SSSSS OO OO FFFFF TT WW W WW AAAAAAAA RRRRRRR EEEEEE **
** SS OO OO FF TT WW W WW AA AA RR RR EE **
** SSSSSS OOOOOO FF TT WWWWW AA AA RR RR EEEEEEEE **
** **
*********** NOTICE ************************************************************
** This file contains valuable trade secrets and proprietary **
** assets of Windbase Software Inc. Embodying substantial **
** creative efforts and confidential information. Unauthorized **
** use, copying, decompiling, translating, disclosure or **
** transfer, of any kind, is strictly prohibited. **
** **
** COPYRIGHT (C) 1992, 1993, 1994. Windbase Software Inc. **
** ALL RIGHTS RESERVED. **
\*****************************************************************************/
/*************************************************************************\
**** Array Demo **********************************************************
**
** This is an example of using the MemSL array allocator. Arrays
** of any size and dimension can be dynamically allocated during
** runtime. To allocate an array simply call WBArrayOpen(). To
** free the array call WBArrayClose(). To access the array call
** WBArrayArray(), this will return a pointer to the array
** allocated. You will notice that for each dimension in the array
** you have to define the '*', so for a two dimensional array you
** will need '**array' just like the 'argv' command line argument,
** likewise you will need to define '**********Array' for a ten
** dimensional array. The WBArray allocates memory across segments
** on MS-DOS machines and therefore you have access to all the
** available memory of your system.
**
\*************************************************************************/
#include <stdio.h>
#ifdef HAS_UNISTD_H
# include <unistd.h>
#else
# include <stdlib.h>
#endif
#include "../../memsl.h"
#ifdef WBSTDC
int main(void)
#else
int main()
#endif
{
WBARRAY *array; /* Array structure used for tracking the */
/* dimensions, sizes and memory returned */
/* during the open call. */
char **********strarray; /* Ten dimensional character array. */
int i1, i2, i3, i4, i5, i6, i7, i8, i9; /* Temporary integers used */
/* to set and print the */
/* elements of the array. */
/*
** WBArrayOpen() allocates the memory for the array and
** returns a pointer to a WBARRAY structure which contains
** the array and the information used to allocate and
** deallocate the array.
*/
#if defined(WBMEMTRACE) || defined(WBUSERMEM)
if (getenv("WBOVRCHK") || getenv("WBMEMCHK"))
{
printf("This program will run extremely slow with the WBOVRCHK\n");
printf("and WBMEMCHK environment variables set. Please unset\n");
printf("these environment variables.\n\n");
exit(1);
}
#endif
if ((array = WBArrayOpen(NULL,"2,2,2,2,2,2,2,2,2,40")) != NULL)
{
/*
** WBArrayArray() simply returns the array. The return
** value should be assigned to a variable capable of
** accessing each dimension. At this point we can use the
** array as though it were a predefined array.
*/
strarray = WBArrayArray(array);
for (i1 = 0; i1 < 2; i1++)
for (i2 = 0; i2 < 2; i2++)
for (i3 = 0; i3 < 2; i3++)
for (i4 = 0; i4 < 2; i4++)
for (i5 = 0; i5 < 2; i5++)
for (i6 = 0; i6 < 2; i6++)
for (i7 = 0; i7 < 2; i7++)
for (i8 = 0; i8 < 2; i8++)
for (i9 = 0; i9 < 2; i9++)
sprintf(strarray[i1][i2][i3][i4][i5][i6][i7][i8][i9],
"10 dimensional array %d%d%d%d%d%d%d%d%d",
i1,i2,i3,i4,i5,i6,i7,i8,i9);
for (i1 = 0; i1 < 2; i1++)
for (i2 = 0; i2 < 2; i2++)
for (i3 = 0; i3 < 2; i3++)
for (i4 = 0; i4 < 2; i4++)
for (i5 = 0; i5 < 2; i5++)
for (i6 = 0; i6 < 2; i6++)
for (i7 = 0; i7 < 2; i7++)
for (i8 = 0; i8 < 2; i8++)
for (i9 = 0; i9 < 2; i9++)
printf("%s\n",strarray[i1][i2][i3][i4][i5][i6][i7][i8][i9]);
/*
** Once we are through with the array we need to deallocate
** the array. Notice we do not free the 'strarray'
** variable, this is because the array belongs to the
** WBARRAY structure.
*/
WBArrayClose(array);
}
exit(0);
return(0);
}