DPRG List  

[DPRG] C programming problem, large arrays in 16 bit DOS?

Subject: [DPRG] C programming problem, large arrays in 16 bit DOS?
From: Doug Evans douglasee at worldnet.att.net
Date: Mon Aug 18 18:13:00 CDT 2003

A couple of observations:

First, do you need an unsigned char to store a single pixel? If this is a
0/1 value rather than a grayscale value, you could map each pixel to a bit.
This will reduce your memory requirement by a factor of 8 and effectively
eliminate the issue.

Second, switch to "large" memory model, and declare the array as "huge". I
don't remember exactly how to do this using Borland under DOS (it's been
awhile), but I do know that I have done it before. Under DOS, you are
limited to 64K segments of memory for a single data structure. This is a
fundamental issue with the x86 architecture. The "huge" directive manages
the larger structure under the covers for you.

I'm not certain that you can safely ignore the "never used" warning. I don't
think the compiler will guarantee that all of the memory will be contiguous,
since each array will be in a separate data segment.


-----Original Message-----
>From: dprglist-admin at dprg.org [mailto:dprglist-admin at dprg.org]On Behalf
Of Clay Timmons
Sent: Monday, August 18, 2003 4:08 PM
To: dprglist at dprg.org
Subject: [DPRG] C programming problem, large arrays in 16 bit DOS?

I'm working on the image processing code on my robot and I have a new
The problem is dimensioning the image array.  The image is 320x240 pixels
and each pixel is stored in a byte (unsigned char).  The problem is that
I'm using 16 bit DOS (sorry I promise to move to Linux once I get those
My declaration is like this.  I'm using Borland C v4.52

  unsigned char   camera_image[76800];

This gets an error that the constant is too large.  Anything dimensioned
[32767] gets this error.

So then I thought well I'll just break up the array into three smaller
and pray the compiler puts them one after another in memory.  I figure this
should work fine since I only access the array with a pointer,  image_ptr++

  unsigned char   camera_image[30000];
  unsigned char   camera_image2[30000];
  unsigned char   camera_image3[30000];

Now the compiler is giving a warning that the last two are declared and
never used.
It's probably optimizing them away so I added some bogus code that uses
Still it's not working quite right yet.

I just want to make sure the compiler reserves enough space in memory!
I think all the code is correct since it works for smaller sized images
like 160x120 or 80x60.

Any ideas are appreciated,

-Clay Timmons-

DPRGlist mailing list
DPRGlist at dprg.org

More information about the DPRG mailing list