hi,

in turbo C the maximum array size i am able to specify is array[250][250]..
what should i do to enlarge this size to say..array[512][512]..
i dont know a thing about memory allocation,
so please help me out/.. :-|

Recommended Answers

All 13 Replies

Turbo C is a very old DOS compiler.
250*250 just happens to be very near the maximum value for a 16 bit unsigned int which is what under DOS is used as a pointer.

Use a 32 bit compiler if you want to allocate larger arrays.

WAT YOU CAN DO IS JUST LIKE SUGESTED USE A NEWST COMPILER AND CHANGE YOUR DATA TYPE OF YOUR ARRAY. LIKE IF IT WAS INT ARRAY CHANGE IT TO long int array[] or unsigned long int array[];
hope i have helped you out.
any more queries just post it here or pm any of us :confused:

hi,
is there no procedure wherein you can allocate memory by malloc etc..
my whole code is in TorboC and i cant change it to another compiler.(atleast now)..

thanks........

so the only thing to do is use turco c++ modify the code. it is possiblle

why can't you use another compiler?
Cost can't be an issue as there are several modern compilers available free of charge.
Or are you stuck on a machine running DOS?

you should have at least 1 reason 4 not being able to change your code;

is there no procedure wherein you can allocate memory by malloc etc..

Yes. What have you tried?

there is a procedure. the problem is that i cant teach u that coz i myself didnt qiute understand it. i saw that in a book sooo .. maybe somebody else CAN GIVE U A HELPING HAND

why can't you use another compiler?
Cost can't be an issue as there are several modern compilers available free of charge.
Or are you stuck on a machine running DOS?

i am using Turbo C 3.0, when you say another compiler, what do you mean,
can you name some good free downloadable ones..

i am using Turbo C 3.0, when you say another compiler, what do you mean,
can you name some good free downloadable ones..

http://www.compilers.net/

Yes. What have you tried?

#include <stdio.h>
#include <conio.h>
#include <alloc.h>
#include<process.h>

int main(void)
{

FILE *fp;
int n,r,c;
unsigned char *array[256];
clrscr();
//allocate memory
for(n=0;n<256;n++)
	{
		if((array[n]=(unsigned char*) malloc (sizeof(unsigned char)*256))== NULL)
		{
			printf("Not enough memory to allocate buffer\n");
			getch();
			exit(1);  /* terminate program if out of memory */
		}
	}

	if((fp = fopen("f16.dat","r")) == NULL)
	{
		printf("Unable to open the specified file.\n");
		getch();
		exit(1);
	}
	else
	{
		for(r=0;r<256;r++)
		{
			for(c=0;c<256;c++)
			{
				array[r][c]=(unsigned char) fgetc (fp);
			}
		}
		fclose(fp);
		printf("%c\n",array[55][55]); //a sample to check

	//free malloc
	for(n=0;n<256;n++)
	{
		free(array[n]);
	}
}
getch();
return(0);
}

this is what i tried to allocate memory for the 2d array..
but it gives a error, insufficient memory..
i compiled in large memory model in turbo C..
whats the problem :?:

Maybe this will be the repartee, try char instead of int, very old code, but it is Turbo C ...

/********************  fararray.c  ***********************
**
**  Examination of the limits of global variables:
**  Behaviour of two large arrays exceeding the 64k limit.
**    one far global array + one local array
**  Written in Turbo C V.2.0 by dns 6/15/89
**
********************************************************/

#define ASIZE  17000

int far array1[ASIZE]; /* put array far, to next 64k segment */

/*
 The two arrays combined exceed 64k bytes memory, array1 is global,
 array2 is local, but array1 is loaded into its own 64k segment,
 so there is no interference.
 If array1 exceeds 64k space itself, use huge instead of far.
*/

int main(void)
{
  unsigned int array2[ASIZE];
  int k;

  for (k = 0; k < ASIZE; k++)     /* load array1 with 0 to ASIZE */
    array1[k] = k;
  for (k = 0; k < ASIZE; k++)     /* load array2 30000 to 30000+ASIZE */
    array2[k] = k + 30000;
  printf("last 100 values of array1 (16900 - 16999) =\n");
  for (k = (ASIZE-100); k < ASIZE; k++)
    printf("%8u",array1[k]);
  printf("\n\nfirst 100 values of array2 (30000 - 30099) =\n");
  for (k = 0; k < 100; k++)
    printf("%8u",array2[k]);
  getchar();  
  return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.