[comp.sys.amiga] Large string variables in C.

DA3721A@acad.drake.edu (01/04/91)

Hello C programmers,
	I am currently working on a C program that requires the usage of
several very large strings (~10 strings of 1000+ characters each). Do I need
to use AllocMem or some other memory routine to allocate memory for these
strings or am I safe if I do not?

			David Aschbrenner
			DA3721A@drake.bitnet

dcl@ncsc1.ATT.COM (Dave Love) (01/05/91)

In article <40546@nigel.ee.udel.edu> DA3721A@acad.drake.edu writes:
>Hello C programmers,
>	I am currently working on a C program that requires the usage of
>several very large strings (~10 strings of 1000+ characters each). Do I need
>to use AllocMem or some other memory routine to allocate memory for these
>strings or am I safe if I do not?

This is probably a better question for comp.lang.c, so I've redirected 
the followups there.

Basically, you have three options:

1.  Declare the strings statically (outside of any funtions, or by using 
	 the 'static' keyword):

	 char string[10][1000];
    void main() {...};

2.  Declare the strings within a function ('auto'):

	 void main()
	 {
		 char string[10][1000];
       ...
    }


	 Note: on the Amiga you will need to set a large stack size in order
	 for this to run (say STACK 30000).  Otherwise you WILL crash the 
	 system.

3.  Declare the strings dynamically:

	 void main()
	 {
		 int i;
		 char *string[10];
		 for (i = 0; i < 10; i++)
			string[i] = malloc(1000);
			/* or, for the Amiga:  string[i] = AllocMem(1000,0); */
       ...
    }

>
>			David Aschbrenner
>			DA3721A@drake.bitnet


-- 
 Dave Love  
 UUCP: dcl@ncsc1.att.com  CI$: 75126,2223   bix: dlove  

 -- "MS-DOS... The ultimate PC virus." --