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