barbarin@Xerox.com (Mike Barbarino) (12/15/90)
I'm having some problems with TC++ ... in particular with the following sort of thing: const DBSIZE = 31000; struct weights { unsigned long x; unsigned long y; }; long memsize; ... memsize = DBSIZE * sizeof(weights); weights huge *accumulator = (weight *)farmalloc(MEMSIZE); ... for (int j=0; j<DBSIZE; j++, accumulator++) { accumulator->x = 255; if (accumulator->x != 255) .... ... } ... and so on... In the IDE, using the debugger, I can trace over the assignment of the '255' without a watch on accumulator->x showing a change. A check immediately after the assignment shows no change. By deleting an element in the structure (say y), recompiling, etc., the assignment works. What am I doing wrong? Thanks in advance...
water1@blake.u.washington.edu (Dongxia Li) (12/15/90)
In article <678@roo.UUCP> barbarin@Xerox.com (Mike Barbarino) writes: >I'm having some problems with TC++ : const DBSIZE = 31000; struct weights { unsigned long x; unsigned long y; }; weights huge *accumulator = (weight *)farmalloc(MEMSIZE); ... By deleting an element in the structure (say y), recompiling, etc., the assignment >What am I doing wrong? Thanks in advance... Your data block is larger than 64k limit. Read HELPME!.doc come with the compiler for instruction to handle this kind of problem. // ************************************************************************* // Hong Li // water@blake.u.washington.edu // *************************************************************************
quimby@itsgw.rpi.edu (Tom Stewart) (12/16/90)
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.