Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!rpi!quimby From: quimby@itsgw.rpi.edu (Tom Stewart) Newsgroups: comp.lang.c++ Subject: Re: TC++ problem w/huge arrays of struct? Keywords: TC++; arrays; pointers; struct; Message-ID: <8#H^*~&@rpi.edu> Date: 15 Dec 90 16:30:16 GMT References: <678@roo.UUCP> <13035@milton.u.washington.edu> Organization: Rensselaer Polytechnic Institute, Troy NY Lines: 41 Nntp-Posting-Host: madoka.its.rpi.edu A couple of corrections are in order. In a previous post I stated that static data in TC++ is limited to 64k. This is incorrect, as of TC++ v1.0 -- Static data >64k, including arrays >64k, is supported if explicitly declared as 'far' or 'huge', respectively. In article <678@roo.UUCP> barbarin@Xerox.com (Mike Barbarino) writes: >I'm having some problems with TC++ : > const DBSIZE = 31000; > long memsize; > struct weights { > unsigned long x; > unsigned long y; > }; > > memsize = DBSIZE * sizeof(weights); > weights huge *accumulator = (weight *)farmalloc(MEMSIZE); Mike writes of problems accessing accumulator[]. The problem here is that both sizeof() and DBSIZE are int's, so the calculation of memsize is done as int, then assigned to memsize. The fix is to either cast something to long before multiply, or change DBSIZE to long. TC++ *will* allocate >64k blocks with farmalloc(). Be sure to check against NULL, and don't expect to be able to run programs allocating large amounts of memory under the IDE. The 64k limit of Turbo C++ exists only with memory allocated with 'new' or malloc(). Although >64k statics require explicit declaration, IMHO this isn't much of a problem. The 'new' limit, however, is highly annoying. Quimby (mailer disfunctional, replies to: quimby@mts.rpi.edu, quimby@rpitsmts.bitnet) NOTE: Although statics >64k seem to allocate correctly, they still generate 'stack overflow' messages at run time if TC++'s stack checking is enabled. At this point I'm not certain if it's a problem with my code, the allocation, or the stack checking.