Large arrays in MSDOS
BEN PEDERSEN
ben.pedersen at canremote.uucp
Fri Oct 27 05:56:00 AEST 1989
Howdy Scott,
Your message said,
SM>I've been having a problem trying to use an array greater than 64k
SM>on an msdos machine. What I have is the following:
SM>char foo;
SM>char FAR *bigbuf;
SM>.
SM>.
SM>.
SM>bigbug=farmalloc(125000L);
SM>Then, I try to use bigbuf as a linear array:
SM>bigbuf((long) some_pointer*some_num) = foo;
SM>(I have compiled using the D model)
SM>I am having problems with getting this to work, and I'm not sure if
SM>it's something in my implementation, or my whole method is bogus.
SM>Does anyone out there know if this should work?
I'm not sure which compiler you are using or what the 'D model'
represents but I put together the following using Zortech C under the
small memory model,
#include <stdio.h>
#include <dos.h>
main()
{
char foo;
char far *bigbuf;
unsigned long some_num;
foo = 'A';
some_num = 85000L;
printf("\n%lu bytes of memory available\n", farcoreleft());
if((bigbuf = (char far*)farmalloc(125000L)) == NULL) {
printf("\nfarmalloc failed!\n");
exit(1);
}
printf("\nuninitialized: *(bigbuf + some_num) == \'%c\' \
(ie. garbage)\n",*(bigbuf + some_num));
*(bigbuf + some_num) = foo; /* assign 'A' to a bigbuf location */
printf("\n initialized: *(bigbuf + some_num) == \'%c\' \
(ie. the right stuff)\n",*(bigbuf + some_num));
farfree(bigbuf);
}
It produced the following output on my system,
412032 bytes of memory available
uninitialized: *(bigbuf + some_num) == 'l' (ie. garbage)
initialized: *(bigbuf + some_num) == 'A' (ie. the right stuff)
I am not quite sure about everything you seem to be attempting to do in
this statement,
SM>bigbuf((long) some_pointer*some_num) = foo;
Since you aren't using indirection to dereference the pointer 'bigbuf',
(ie. specify lvalue assignment) this would fail. The statement, as it
is, is attempting to tell the compiler to assign the address of 'foo' to
'bigbuf' (and something I cannot decipher).
'bigbuf' is a pointer and to use the address space it points to as a
linear array you must make use of pointer arithmetic. Locations within
that address space are relative to 'bigbuf'.
When assigning the pointer returned by farmalloc() to a pointer to far
character you should perform explicit type conversion on that returned
pointer because otherwise it is of type void (ie. unspecified type).
As my example attempts to point out, the contents of bigbuf's address
space are uninitialized garbage until it is explicitly initialized.
I hope this is the type of information you were looking for. If not let
me know if I can be more specific.
Ben Pedersen, Sysop
C-Power BBS
---
* QDeLuxe 1.10 #2134 We're just tourists here making fools of ourselves
More information about the Comp.lang.c
mailing list