home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / cplus / 13411 < prev    next >
Encoding:
Text File  |  1992-09-08  |  2.4 KB  |  96 lines

  1. Path: sparky!uunet!spool.mu.edu!agate!ames!data.nas.nasa.gov!taligent!apple!moon!gordie
  2. From: gordie@kaleida.com (Gordie Freedman)
  3. Newsgroups: comp.lang.c++
  4. Subject: Question on Borland C++ and new
  5. Message-ID: <72179@apple.Apple.COM>
  6. Date: 9 Sep 92 01:38:46 GMT
  7. Sender: daemon@Apple.COM
  8. Reply-To: gordie@kaleida.com
  9. Organization: Happy hacker bait and tackle shop
  10. Lines: 84
  11.  
  12. I am using Borland's latest C++ on DOS, and when I try to "new" storage it sometimes returns 0, even though I haven't used that much storage from the heap yet.
  13.  
  14. The case is that I "new" about 32kbytes in 8 calls to new, and then make a call to 
  15. new for another 40k. Suspiciously it looks like I either exceeded 64k and new 
  16. will only give me 64k of storage, or I need to use "far" pointers.
  17.  
  18. The code I wrote runs fine on the Sparc, and is supposed to be platform independant,
  19. so I don't want to muck up the code with far, so I'm hoping there is some way to 
  20. tell the compiler to generate far pointers all the time. Here's an example:
  21.  
  22. // In Object.H
  23.  
  24. class Object {
  25. // This object is 10 bytes in size
  26. private:
  27.     char data [10] ;
  28. public:
  29.     const char* const getData (void) const { return data ; }
  30. } ;
  31.  
  32.  
  33. class Thing {
  34. public:
  35.     void allocate (int num) ;
  36.     Object* get (int index) const { return &objects[index] ; }
  37. private:
  38.     Object* o1 ;
  39.     Object* o2 ; 
  40.     Object* o3 ;
  41.     Object* o4 ; 
  42.     Object* o5 ;
  43.     Object* o6 ; 
  44.     Object* o7 ;
  45.     Object* o8 ; 
  46.  
  47.     Object* objects ;
  48. } ;
  49.  
  50. // In Object.C
  51.  
  52. void Thing::allocate (int num) 
  53. {
  54.     o1 = new Object [num] ;
  55.     o2 = new Object [num] ;
  56.     o3 = new Object [num] ;
  57.     o4 = new Object [num] ;
  58.     o5 = new Object [num] ;
  59.     o6 = new Object [num] ;
  60.     o7 = new Object [num] ;
  61.     o8 = new Object [num] ;
  62.  
  63.     // The next allocate fails, at least objects is set to 0 after it
  64.     // Do I need to make objects "Object far* objects" to house a 4 byte
  65.     // pointer?
  66.     objects = new Object [num * 10] ;
  67. }
  68.  
  69. int
  70. main (unsigned int argc, char** argv)
  71. {
  72.     Thing thing ;
  73.     thing.allocate (400) ;
  74.     return 0 ;
  75. }
  76.  
  77. So I could do this:
  78.  
  79. #ifdef DOS
  80. #define FAR far
  81. #else
  82. #define FAR
  83. #endif
  84.  
  85. and then make all of the pointers far pointers. I'd rather not do this though.
  86. Actually, I'm not sure if my theroy on "far" is even right, I may be doing 
  87. something else wrong. 
  88.  
  89. Any suggestions? I'm having trouble with our newsreader (the server actually), so 
  90. email is preferred if possible. Thanks in advance ...
  91.  
  92. ---
  93. Gordie Freedman: gordie@kaleida.com Sigs are for kids
  94.  
  95.  
  96.