home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / os / mswindo / programm / misc / 4309 < prev    next >
Encoding:
Text File  |  1992-12-17  |  3.2 KB  |  87 lines

  1. Newsgroups: comp.os.ms-windows.programmer.misc
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!csc.ti.com!tilde.csc.ti.com!mksol!duitz
  3. From: duitz@mksol.dseg.ti.com (mitchel n duitz)
  4. Subject: Re: Borland and Memory
  5. Message-ID: <1992Dec17.160015.24323@mksol.dseg.ti.com>
  6. Organization: Texas Instruments, Inc
  7. References: <BzAyI5.BrH@world.std.com> <1992Dec15.144205.16197@mksol.dseg.ti.com> <1992Dec16.182513.5844@panix.com>
  8. Distribution: usa
  9. Date: Thu, 17 Dec 1992 16:00:15 GMT
  10. Lines: 75
  11.  
  12. In article <1992Dec16.182513.5844@panix.com> rryan@panix.com (Rob Ryan) writes:
  13. >In <1992Dec15.144205.16197@mksol.dseg.ti.com> duitz@mksol.dseg.ti.com (mitchel n duitz) writes:
  14. >
  15. >>I seem to have a point in my code, where I am stuck.
  16. >>
  17. >>I do a lot of new and delete inside my code, and first,
  18. >>I do see a memory leak somewhere, but I can;t pin it down.
  19. >>
  20. >>The problem I have is that the program just spins.  This
  21. >>can happen in two different places - either when I declare ofstream ofs(name),
  22. >>or when I'm in a loop allocating a 2 dimensional array - similar to the
  23. >>following
  24. >>
  25. >> [ ... code deleted ... ]
  26. >
  27. >As recommended by another user, make sure that you're using a memory model
  28. >large enough to support all the data you're using.  Also, make sure you
  29. >check the results of the "new" allocation so you can determine if everything
  30. >works or not, and report a failure when it does occur.
  31. >
  32. >I wanted to try this out, though, and got some curious results.  I initially
  33. >tried Borland's EasyWin and kept on getting GPFs.  So, while the command
  34. >line versions of Borland C++ v3.1 and MSC v7.0 dealt with the following code
  35. >fine (reporting errors allocating at row 14, which makes sense given how
  36. >much data I'm allocating).  And when I tried from Windows, Microsoft's
  37. >QuickWin worked fine, too (reporting allocation failure at row 12, which
  38. >also makes sense due to overhead of Windows processing).  What failed to
  39. >work was Borland's EasyWin.  It got a GPF when I tried this program with it.
  40. >I don't know why, though, since the code seems safe.  I presume this is a
  41. >bug in EasyWin's memory allocation routines.
  42. >
  43. >Assuming that you're not using EasyWin, you'd presumably want something
  44. >like the following.  Incidentally, when I decrease the numbers to 150 and
  45. >30, the program works without incident.  And I don't know why the ofstream
  46. >would be causing a problem.  Have you tried running the code through a
  47. >debugger and seeing where the problem occurs?
  48. >
  49. >-------------------------------- cut here --------------------------------
  50. >
  51. >#include <iostream.h>
  52. >
  53. >const long MAXX = 1000;
  54. >const long MAXY = 1000;
  55. >
  56. >main()
  57. >{
  58. >    float **pn = new float *[MAXX];
  59. >
  60. >    if (!pn) {
  61. >        cerr << "failed initial allocation";
  62. >        return -1;
  63. >    }
  64. >
  65. >    for (int i = 0; i < MAXX; i++) {
  66. >        pn[i] = new float[MAXY];
  67. >        if (!pn[i]) {
  68. >            cerr << "failed allocation of row " << i << endl;
  69. >            return -2;
  70. >        }
  71. >    }
  72. >
  73. >    return 0;
  74. >}
  75. >
  76. >-- 
  77. > Rob Ryan
  78. >    rryan@panix.com
  79.  
  80. I'm using The Large Model in the program, and the allocation
  81. works fine the first time I use the object, then when i delete
  82. the object that uses all the memory, and try again it bombs.
  83. I am freeing the memory delete[] pn.   So I don;t know
  84. what's going on.  I even looped through with the debugger, and
  85. then it got to a magic row and it locked up. Thanks.
  86.  
  87.