Arrays [256][256] --- error Array size too large! 
Author Message
 Arrays [256][256] --- error Array size too large!

how can I get around this array size too large error my compiler
borland 3.1 is giving me on the dos machine? I need speed!
but this simple problem is a headache.

Chuck


.



Tue, 02 Jul 1996 23:35:50 GMT  
 Arrays [256][256] --- error Array size too large!
I change your model to large or huge.  You may still have some strange problems with
DOS 6.0 because BC3.1 doesn't seem to recognize the new EMM with it.  One solution
is to use the C++ syntax for new and delete.


Wed, 03 Jul 1996 05:31:11 GMT  
 Arrays [256][256] --- error Array size too large!

Quote:
>how can I get around this array size too large error my compiler
>borland 3.1 is giving me on the dos machine? I need speed!
>but this simple problem is a headache.

RTFM.  Use the huge model.  Better yet, throw out your compiler and
get djgpp from oak.oakland.edu:/pub/msdos/djgpp.  Use it and you
forget about all the {*filter*}the PC makes you put up with.

--
#include        <standard.disclaimer>
 _
Kevin D Quitt 91351-4454                96.37% of all statistics are made up



Wed, 03 Jul 1996 07:29:43 GMT  
 Arrays [256][256] --- error Array size too large!

Quote:
>how can I get around this array size too large error my compiler
>borland 3.1 is giving me on the dos machine? I need speed!
>but this simple problem is a headache.

Try huge arrays in the HUGE memory model, and if that does not work,
switch to a large flat memory model operating system like UNIX or VMS
or something. If you have a 386 or higher, use Linux as an alternative.

I know this sounds flippant, and I apologize for that, but the fact is
that DOS is simply not geared for simple uses of C for large data sets
in this way. You have to muck around with extended and/or expanded
memory systems using DOS extenders like Phar Lap (among others). And
this headache is simply not worth the pain, IMHO.

                                                                Z

--
-------------------------------------------------------------------------
| Syed Zaeem Hosain          P. O. Box 610097            (408) 441-7021 |

-------------------------------------------------------------------------



Wed, 03 Jul 1996 13:45:55 GMT  
 Arrays [256][256] --- error Array size too large!

Quote:

> how can I get around this array size too large error my compiler
> borland 3.1 is giving me on the dos machine? I need speed!
> but this simple problem is a headache.
> Chuck


Can you set your compiler to use the large or huge memory models?
If your matrix is anything larger than char[256][256], you may have
to use ragged arrays instead, due to the memory segmentation
scheme on Intel 80x86 microprocessors. Here's how to make a large
matrix of double's (up to 8192 rows x 4096 columns):

double** allocmatrix(int nrows, int ncols)
{
        double** matrix;
        int i, j;

        if (nrows < 1 || ncols < 1) return 0;

        matrix = (double**)malloc((nrows + 1) * sizeof(double*));
        if (!matrix) return 0;

        for (i = 0; i < nrows; i++) {
                matrix[i] = (double*)malloc(ncols * sizeof(double));
                if (!matrix[i]) goto oops; /* goto's are for error handling! */
                for (j = 0; j < ncols; j++) matrix[i][j] = 0.0;
        }

        matrix[nrows] = 0; /* for freematrix()'s benefit */
        return matrix;

oops:
        while (i--) free(matrix[i]);
        free(matrix);
        return 0;

Quote:
}

void freematrix(double** matrix)
{
        int i;

        if (!matrix) return;

        for (i = 0; matrix[i]; i++) free(matrix[i]);
        free(matrix);

Quote:
}

If you know for a fact that Borland 3.1's malloc() takes a size
parameter of unsigned int, you can change the types of nrows and
ncols to unsigned and allocate matrixes up to 16384x8192. Oops, I
forgot about the 640KB limit! Well, you're not going to get much
beyond a 256x256 matrix of doubles in DOS anyway, since that's
513KB with the above scheme, assuming sizeof(double) == 8 and
sizeof(X*) == 4 for any type X, and not including malloc()'s
overhead, typically only 4 or 8 bytes per memory chunk allocated.

If you need *real* power, either get a DOS-extending compiler
or a real operating system like Linux or Coherent. Those should
let you avoid stuff like the above without too much cost.

--

WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!



Thu, 04 Jul 1996 07:34:09 GMT  
 Arrays [256][256] --- error Array size too large!

Quote:

>>how can I get around this array size too large error my compiler
>>borland 3.1 is giving me on the dos machine? I need speed!
>>but this simple problem is a headache.
>RTFM.  Use the huge model.

        Et tu, Kevin?

        The maximum size of an array that can be defined on _any_ system is
bounded by the type of size_t.

        T max_array[(size_t)-1 / sizeof (T)];

        is the maximum array of type T you can declare.

        BC has hard-coded size_t to be unsigned int (irrespective of the memory
model), so the maximum array size is going to be 64K - 1 for char type. Changing
to the huge model won't help, unless you are ready to use the non-portable
"huge" array declarations (they won't port even to earlier versions of Turbo C).

        Even though char Array[UINT_MAX]; is a valid declaration under any
memory model, (&Array[j] - Array) might not necessarily yield the value of j.
This subtraction is valid only if the value of 'j' falls in the range
represented by the type ptrdiff_t (which is signed int for the small model).
This means that the effective max size of the array you can declare in this
model is restricted to 32767 (unless you are ready to go to the extra pain of
ensuring subtractions like the one above are scrupulously avoided).

-----
/* The right answer is not always the one that is desired. */

/* Ajoy Krishnan T,
   Software Engineer, Hughes Software Systems,
   New Delhi - 19, India.



Fri, 05 Jul 1996 23:12:00 GMT  
 Arrays [256][256] --- error Array size too large!

Quote:
>how can I get around this array size too large error my compiler
>borland 3.1 is giving me on the dos machine? I need speed!
>but this simple problem is a headache.

Well, there are a couple of solutions that occur to me.

1)  Check to make sure you're using the large memory model.  This MAY make a
    difference.

2)  Try using a sparse array instead of allocating each cell.  Do you really
    have valid data values in EVERY cell?  Sparse arrays are much more
    efficient, memory-wise and may even be faster, depending upon your algorithm.

Just a few thoughts.



Sun, 07 Jul 1996 11:08:24 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. displaying 256 color bitmaps when screen is in 256 color mode

2. showing 256 color bitmaps with display settings set to 256 colors

3. displaying 256 color bitmap in 256 color mode

4. Transfer a BYTE value of 256 size to DLL function

5. How to display a 256 color bitmap on a button so shows with 256 colors?

6. How to display a 256 color bitmap on a button so shows with 256 colors?

7. 256 color bitmaps get remapped with 16 color palette when using 256 color display?

8. Marshal::StringToHGlobalAnsi corrupts output after 256 chars

9. getchar and 256 char hangup

10. need help displaying 256 color bitmaps

11. 256 BGI drivers wanted!!!

12. breaking the 256 color barrier ... plz help

 

 
Powered by phpBB® Forum Software