[comp.windows.ms.programmer] What to do when > 64k of c++ objects

parks@maxwell.physics.purdue.edu (Chris Parks) (06/19/91)

Ok, here's the deal: say you're using the medium model to write a c++
program for windows and you will be using a lot of dynamically allocated
objects created with the new operator.  Since this returns a near pointer
you only are allowed 64k worth of objects.  I would like to be able to use
many complex objects which all together will exceed 64k.  It's my  
understanding that if I switch to the large model the new operator will
create hundreds of tiny memory obstacles which windows won't be able to move.
All c++ programming examples I've seen for windows seem to be using the 
new operator in a carefree way without any concern for running out of space.
Does anyone have any tips on handling a large number of objects?

Thanks,
Chris Parks
parks@maxwell.physics.purdue.edu
 

merrill@cs.arizona.edu (Darren J. Merrill) (06/19/91)

>Ok, here's the deal: say you're using the medium model to write a c++
>program for windows and you will be using a lot of dynamically allocated
>objects created with the new operator.  Since this returns a near pointer
>you only are allowed 64k worth of objects.  I would like to be able to use
>many complex objects which all together will exceed 64k.  It's my  
>understanding that if I switch to the large model the new operator will
>create hundreds of tiny memory obstacles which windows won't be able to move.
>All c++ programming examples I've seen for windows seem to be using the 
>new operator in a carefree way without any concern for running out of space.
>Does anyone have any tips on handling a large number of objects?
>
>Thanks,
>Chris Parks
>parks@maxwell.physics.purdue.edu

  What you can do is write your own new and delete operators (overload them)
that GlobalAlloc the space for the object.  Ummm... lets see, look at page..
137 in the BC++ Programmer's Guide for more details.
However, if you have "tons" of objects, you may not want tie up that many
global handles (only 8192 of them).  Perhaps you could use one handle as a 
static member for the class that points to a block.  Then when you new or
delete, you add/remove an entry from this table.  Needs some thought, might
work though.
Good Luck.

/* ---------------------------------------------------------------------- */
Darren Merrill
merrill@cs.arizona.edu