Malloc'ing > 64kb (in TC)

Mike Percy grimlok at hubcap.clemson.edu
Sun Jun 30 03:36:41 AEST 1991


gomer at spiff.soe.clarkson.edu (Paul Kronenwetter) writes:

>	file=malloc(70000L)

>Granted the syntax for 70000L probably isn't correct just make believe it 
>works.. ;-)  The real problem is that I need both the space and to use the
>str??? functions.. as well as file[count]=fgetc(infile);  assuming count is
>a long unsigned int > 0xffff... Does anyone see a way to do this or am I 
>going to have to write my own routines (gasp) to do this sort of thing using
>far pointers & farmalloc...
 
Huh? Excuse me while I try to figure this out...you are aware of far
pointers and far*alloc functions in TurboC(++), but you want to write
your own functions to malloc > 64K?  How about try:
  
     stuff far *file;
     file = (stuff far *)farmalloc(70000L); 

Actually, to acces >64K, you need to use huge rather than far:
  
     stuff huge *file;
     file = (stuff huge *)farmalloc(70000L);

Now this will work...
     long i;
     for(i = 0; i < 70000L; i++)
        file[i] = /* whatever */;

If this is too much try:

#define malloc(x) farmalloc((x))

You'll still need to use huge pointer to acces it though.  By the way,
in large data memory models, malloc is fed by farmalloc anyway,
esentially being this:
 
  void far *malloc(size_t size)
  {
     return farmalloc((long)size);
  }

One last thing, when posting compiler-specific questions, which most
often don't belong in c.l.c anyway,  it's polite to put the compiler
name in the subject line.  This will let people skip messages that don't
pertain to them.

"I don't know about your brain, but mine is really...bossy."
Mike Percy                    grimlok at hubcap.clemson.edu
ISD, Clemson University       mspercy at clemson.BITNET
(803)656-3780                 mspercy at clemson.clemson.edu



More information about the Comp.lang.c mailing list