home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12722 < prev    next >
Encoding:
Internet Message Format  |  1992-08-21  |  1.6 KB

  1. Path: sparky!uunet!usc!elroy.jpl.nasa.gov!ames!agate!dog.ee.lbl.gov!network.ucsd.edu!sdcc12!sdcc3!acanter
  2. From: acanter@sdcc3.ucsd.edu (Adriaan Canter)
  3. Newsgroups: comp.lang.c++
  4. Subject: Turbo C++ Memory Managment On the PC
  5. Keywords: Memory Heap
  6. Message-ID: <37103@sdcc12.ucsd.edu>
  7. Date: 21 Aug 92 13:22:12 GMT
  8. Sender: news@sdcc12.ucsd.edu
  9. Distribution: ca
  10. Lines: 23
  11. Nntp-Posting-Host: sdcc3.ucsd.edu
  12.  
  13.  
  14. Hello, I've noticed that Borland Turbo C++ (v 1.0) will actually reserve 16
  15. bytes when the "new" function is used to allocate space for a 2 byte
  16. integer, i.e. the following code:
  17.  
  18. int * intptr;
  19. intptr = new int;
  20.  
  21. will allocate 16 bytes, as measured using the "coreleft()" function,
  22. under the small memory model. A subsequent second allocation of this type will
  23. fit the second integer into the first 16 byte space allocated, but a third call
  24. will block off an additional 16 bytes, and so on, so that 4 two-byte integers
  25. will take up 32 bytes of space, for example. I guess this happens because some
  26. space is reserved to point to the next location in the heap, although the
  27. amount seems excessive. This is pretty wasteful of course, if I want to
  28. dynamically allocate alot of structures. Is there anyway I can control how
  29. much memory is actually reserved when the "new" function is called? Do the
  30. newer versions of C++ have some memory managment classes (as I've over-heard)
  31. that can fix this? Or do I have to finagle my own scheme, overloading the
  32. "new" and "delete" operators. Forgive me if this is a dumb question, but my
  33. manuals don't say very much about it. Thank you.
  34.  
  35.                                         Adriaan Canter
  36.