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

  1. Newsgroups: comp.os.ms-windows.programmer.misc
  2. Path: sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!malgudi.oar.net!news.ans.net!cmcl2!panix!rryan
  3. From: rryan@panix.com (Rob Ryan)
  4. Subject: Re: Borland and Memory
  5. Message-ID: <1992Dec18.052959.6488@panix.com>
  6. Date: Fri, 18 Dec 1992 05:29:59 GMT
  7. Distribution: usa
  8. References: <BzAyI5.BrH@world.std.com> <1992Dec15.144205.16197@mksol.dseg.ti.com> <1992Dec16.182513.5844@panix.com> <1992Dec17.160015.24323@mksol.dseg.ti.com>
  9. Organization: Panix, NYC
  10. Lines: 35
  11.  
  12. In <1992Dec17.160015.24323@mksol.dseg.ti.com> duitz@mksol.dseg.ti.com (mitchel n duitz) writes:
  13.  
  14. >I'm using The Large Model in the program, and the allocation
  15. >works fine the first time I use the object, then when i delete
  16. >the object that uses all the memory, and try again it bombs.
  17. >I am freeing the memory delete[] pn.   So I don;t know
  18. >what's going on.  I even looped through with the debugger, and
  19. >then it got to a magic row and it locked up. Thanks.
  20.  
  21. So, it sounds like the problem isn't in the allocation (because it works the
  22. first time) but the de-allocation.  My understanding is that the construct
  23. "delete [] pn" is used for freeing the memory allocated with something like
  24. "int *pn = new int[100]".  But if you're allocating memory for an array of
  25. pointers and then do subsequent allocations for arrays for the individual
  26. pointers in the first array to point to, don't you have to do something
  27. like:
  28.  
  29.     for (int i = 0; i < MAXX; i++)
  30.     delete [] pn[i];
  31.     delete [] pn;
  32.  
  33. I personally find this sort of confusing, but it that seems like it should 
  34. work.  I don't know why "delete [] pn" by itself doesn't work (I could
  35. see it not freeing the bulk of the data, and destroying the pointers to
  36. a lot of data, but I don't see why that would be fatal).  Perhaps when
  37. you're doing the next loop, the system runs out of memory, does a garbage
  38. collection (of sorts), but since the pointers for some unallocated data
  39. have been destroyed, it gets confused.  Ideas?
  40.  
  41. I really don't know and am just guessing, but does that make sense?  Have
  42. I gone seriously awry here?
  43.  
  44. -- 
  45.  Rob Ryan
  46.     rryan@panix.com
  47.