[comp.lang.c] Allocating Huge Arrays in MSC 5.0

pyt@hprnd.HP.COM (Pierre-Yves Thoulon) (01/06/89)

I guess the problem is with your pointer arithmetic. I don't think the
compiler likes (vector + i) when i is such that the resulting pointer
would cross the 64K boundary. I'd rather use the following:

double huge *vector, huge *index;
int i, number_of_elements, retval;
...

vector = (double *) malloc( number_of_elements * sizeof( double ) );
index = vector;		/* to save the base pointer value */
for( i = 0; i < number_of_elements; i++ )
{
	retval = fscanf(infp,"%lf",index++ );
                                   ^^^^^^^
}

I've had the same kind of problem recently, I was using a vector[i]
notation for a huge vector. It worked fine until I went beyond the 
first 64K limit. Incrementing a pointer as above solved the problem.
(took me a while to figure out... !)

Hope this helps.
Pyt.

wei@hpctdls.HP.COM (Bill Ives) (01/06/89)

   I believe you're having problems due to the 64K boundry crossing 
   just like you mentioned -- but using /AH will not fix it for you
   since that tells the compiler how you want to treat pointers NOT
   data space size.  You have to use the halloc() function to allocate
   any data space larger than 64K ( and have MSC do the pointer
   manipulations for you ).  According to my documentation, if you want
   an array > 128K you must also ensure that the array element size be
   a power of 2.

   Hope this helps ...

   Bill Ives
   HP Colorado Telecommunications Division

   Disclaimer: These are only my opinions, mine mine mine....