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

e89hse at rigel.efd.lth.se e89hse at rigel.efd.lth.se
Tue May 29 05:28:02 AEST 1990


In article <1990May28.000424.20473 at druid.uucp>, darcy at druid.uucp (D'Arcy J.M. Cain) writes:
>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++;}

 Either you had a bad day programing this or you're really lost:

1) 	An int has the range -32768 <= n <= 32767, and 82*2000 is obviously not
	<= 32767 if you're using a 16-bit processor. (Ok we can argue a whole
	lot about that but I guess it's true for this the ase here.)
2)  	 The idea with small memory model is that you use less than 64k of data, 
	otherwise you're probably better off using big model rather than try 
	to fix it, unless you're desperate for performance.
3)	If you really want to minimise the memory usage why do you have a fixed
	array? (Many lines are probably less than 81 characters long.) An 
	array with ptr to ptr or something would probably be more compact.
	
 Mixing memory models isn't easy. If you know what you're doing you'll have a
hard time doing it, otherwise you'll just waste a lot of time.

 Henrik Sandell



More information about the Comp.lang.c mailing list