home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / os / msdos / programm / 10832 < prev    next >
Encoding:
Text File  |  1992-11-21  |  1.9 KB  |  69 lines

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!rutgers!concert!samba!jdmce
  2. From: jdmce@med.unc.edu (Duncan McEwen)
  3. Newsgroups: comp.os.msdos.programmer
  4. Subject: BorlandC++ and dynamic mem allocation
  5. Message-ID: <1992Nov22.014208.2932@samba.oit.unc.edu>
  6. Date: 22 Nov 92 01:42:08 GMT
  7. Sender: usenet@samba.oit.unc.edu
  8. Organization: UNC School of Medicine
  9. Lines: 56
  10. Originator: jdmce@cahaba
  11. Nntp-Posting-Host: cahaba.med.unc.edu
  12.  
  13. Can anyone help me figure out what is going on here?  I am new to 
  14. both C and Borland C++.  Here is an extraction of code from a little
  15. prime generating program I wrote containing, I'm pretty sure, the
  16. offending code.
  17.  
  18. When compiled under the tiny module the program worked ok.  But
  19. I wanted to examine larger ranges of potential primes then about
  20. 5000 numbers possible with the tiny module.
  21.  
  22. So, I switched to the the "compact" compiler option.  Again the
  23. program worked ok, but if I increased numInRange (see Malloc)
  24. to around 10000, the program misbehaved and seemed to wipe out
  25. part of resident command.com.  That is, the program ran ok but
  26. dos was then not able to load command.com
  27.  
  28. Does anyone have an hints as to something obvious I may be missing
  29. that could acount for dynamically allocated memory being so naughty?
  30.  
  31.  
  32. #include <stdio.h>
  33. #include <conio.h>
  34. #include <time.h>
  35. #include <stdlib.h>
  36. #include <ctype.h>
  37. /*#include <sys\timeb.h>*/
  38.  
  39. long i,numInRange,xMax,xMin,temp,firstInRange,divArrayMax;
  40. long divArray[4010];
  41. long *primArray;
  42.  
  43. main ()
  44. {
  45.     ;
  46.     ;
  47.     ;
  48.         
  49.       /*   initialize some variables  */
  50.     if ((primArray = (long *) malloc(numInRange)) == NULL)
  51.        {
  52.         printf("Not enough memory to allocate buffer\n");
  53.         exit(1);  /* terminate program if out of memory */
  54.         }
  55.     for (i = 0; i < numInRange; ++i)
  56.            *(primArray+i) = firstInRange++;
  57.     for (i = 0; i < divArrayMax; ++i)
  58.        divArray[i] = i + 2;
  59.     prime();
  60.     ;
  61.     ;
  62.     ;
  63. }
  64.  
  65. void prime()
  66. {
  67.  
  68. }
  69.