Using small memory model functions on huge arrays (was See below...)

D'Arcy J.M. Cain darcy at druid.uucp
Mon May 28 10:04:24 AEST 1990


In article <90052709560067 at masnet.uucp>
simon.ewins at f664.n250.z1.fidonet.org (simon ewins) writes:
>Given an IBM-PC architecture to work with and limited to a SMALL memory model (for sake of argument) (I realize that using a large memory model takes the problem away!).  The following does not work:
> 
>char huge *files;
>int i;
> 
>files=(char huge *)farmalloc(2000L*82L);
> 
>for (i=0; i<2000; i++)
I think you mean "for (i=0; i<(2000*82); i+=82)"
>   strcpy(&files[i],"Some kind of character string");
> 
>for (i=0; i<2000; i++)
ditto for this
>   puts(&files[i]);
> 
> 
>All I really want to do is find a way to use a small memory model to access
>an array of 2000 strings of 81 bytes in length!
You have to in effect write your own functions.  For example, the strcpy above
can be written as:
#define strcpy(dest, src) {char *s = src, *d = dest; while (*s) *d++ = *s++;}
Of course you would use a name like hstrcpy or something so as not to interfere
with strcpy and you have to watch for side effects but you probably get the
idea.  You can also write it inline if it doesn't happen in too many places.

>All I can see is that in the small memory model one may be able to allocatexi
>data arrays that are bigger than the memory model but the functions that one
>is likely to use to access them are all mapped to NEAR pointers and throw up
>when given pointer arguments longer than 16 bits.  This is true??
Of course.  That's why they call it small model.

> 
>As I said, my real-world solution was to use a large memory model.  However,
>I still feel that somehow one must be able to use the small model (which
>executes much faster due to the smaller code pointers).  Anyone who can get
>the above code to work in a small environment would be thought of quite
>highly if they could share their success with me! Thanks...
> 
 think that something like the above is about the best you can expect.  That
is the trade-off between using different memory models.

-- 
D'Arcy J.M. Cain (darcy at druid)     |   Government:
D'Arcy Cain Consulting             |   Organized crime with an attitude
West Hill, Ontario, Canada         |
(416) 281-6094                     |



More information about the Comp.lang.c mailing list