home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!rutgers!concert!samba!jdmce
- From: jdmce@med.unc.edu (Duncan McEwen)
- Newsgroups: comp.os.msdos.programmer
- Subject: BorlandC++ and dynamic mem allocation
- Message-ID: <1992Nov22.014208.2932@samba.oit.unc.edu>
- Date: 22 Nov 92 01:42:08 GMT
- Sender: usenet@samba.oit.unc.edu
- Organization: UNC School of Medicine
- Lines: 56
- Originator: jdmce@cahaba
- Nntp-Posting-Host: cahaba.med.unc.edu
-
- Can anyone help me figure out what is going on here? I am new to
- both C and Borland C++. Here is an extraction of code from a little
- prime generating program I wrote containing, I'm pretty sure, the
- offending code.
-
- When compiled under the tiny module the program worked ok. But
- I wanted to examine larger ranges of potential primes then about
- 5000 numbers possible with the tiny module.
-
- So, I switched to the the "compact" compiler option. Again the
- program worked ok, but if I increased numInRange (see Malloc)
- to around 10000, the program misbehaved and seemed to wipe out
- part of resident command.com. That is, the program ran ok but
- dos was then not able to load command.com
-
- Does anyone have an hints as to something obvious I may be missing
- that could acount for dynamically allocated memory being so naughty?
-
-
- #include <stdio.h>
- #include <conio.h>
- #include <time.h>
- #include <stdlib.h>
- #include <ctype.h>
- /*#include <sys\timeb.h>*/
-
- long i,numInRange,xMax,xMin,temp,firstInRange,divArrayMax;
- long divArray[4010];
- long *primArray;
-
- main ()
- {
- ;
- ;
- ;
-
- /* initialize some variables */
- if ((primArray = (long *) malloc(numInRange)) == NULL)
- {
- printf("Not enough memory to allocate buffer\n");
- exit(1); /* terminate program if out of memory */
- }
- for (i = 0; i < numInRange; ++i)
- *(primArray+i) = firstInRange++;
- for (i = 0; i < divArrayMax; ++i)
- divArray[i] = i + 2;
- prime();
- ;
- ;
- ;
- }
-
- void prime()
- {
-
- }
-