Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!rex!uflorida!stat!sun13!VSSERV.SCRI.FSU.EDU!mayne From: mayne@VSSERV.SCRI.FSU.EDU (William (Bill) Mayne) Newsgroups: comp.lang.c Subject: Re: Turbo C large character array Keywords: TC, char, array, large, huge Message-ID: <332@sun13.scri.fsu.edu> Date: 30 Jul 90 23:44:11 GMT References: <1990Jul27.193520.4689@ux1.cso.uiuc.edu> <1990Jul30.204053.28769@ux1.cso.uiuc.edu> Sender: news@sun13.scri.fsu.edu Distribution: comp Organization: SCRI, Florida State University Lines: 37 In article <1990Jul30.204053.28769@ux1.cso.uiuc.edu> gordon@osiris.cso.uiuc.edu (John Gordon) writes: > > Well, I managed to solve my problem, with thanks to all who posted and >e-mailed me suggestions. The final solution: > > char huge menu[1200]; > > for(i = 0; i < 1200; i++) > menu[i] = farmalloc(80); > Don't be so hasty about the "final solution." There must be a better way than using 1200 separate calls to malloc or farmalloc! In addition to the time (which admittedly may not be too much of a concern since you only do this once) you should be aware that in most implementations each malloc incurs memory overhead in addition to the storage requested. The system must keep track of all those separate allocations so that when you do the frees later he knows the associated length. The minimum overhead on a PC (which I assume you are using from your description) is usually 16 bytes. You'd do better to allocate a big block and set your own pointers to the individual elements. Something like this: char *hugeblock, *block[1200]; hugeblock=malloc(1200*80); for (i=0; i<1200; ++i) block[i]=hugeblock+80*i; /* rest of your code goes here */ free(hugeblock); This assumes the huge memory model, but with some slight variation you could get by with large, allocating the amount you need in pieces <64K but setting the pointers in block as one array. Also, this is not quite as efficient as it could be because I wanted it to be as clear as possible without long explanations. But I think you can get the idea from this.