home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12459 < prev    next >
Encoding:
Text File  |  1992-08-17  |  1.1 KB  |  44 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!microsoft!hexnut!jimad
  3. From: jimad@microsoft.com (Jim Adcock)
  4. Subject: Re: Allocating arrays larger than 64K with new?
  5. Message-ID: <1992Aug17.225946.12583@microsoft.com>
  6. Date: 17 Aug 92 22:59:46 GMT
  7. Organization: Microsoft Corporation
  8. References: <1992Aug9.152253.11345@newshub.sdsu.edu>
  9. Lines: 33
  10.  
  11. In article <1992Aug9.152253.11345@newshub.sdsu.edu> add@newshub.sdsu.edu (James D. Murray) writes:
  12. >
  13. >Just how does one use 'new' to allocate an array larger than 'size_t'
  14. >bytes in size?
  15.  
  16. Two ideas.  This first one is what I prefer, namely write a "smart array":
  17.  
  18. class HugeArray
  19. {
  20.     void* phugearray;
  21.     HugeArray(long size) { phugearray = huge_alloc(size); }
  22.     ....
  23. };
  24.  
  25. main()
  26. {
  27.     HugeArray* p = new HugeArray(10000000);
  28. }
  29.  
  30.  
  31. Second Idea:  declare a custom new with a "placement" parameter that specifies
  32. the number of elements:
  33.  
  34. void* operator new(size_t size, long nelements)
  35. { return huge_alloc(size*nelements); }
  36.  
  37. main()
  38. {
  39.     double* hugearray = new(1000000) double;
  40. }
  41.  
  42. This second approach has the disadvantage of not calling the "right" 
  43. number of constructors, when used with classes that have constructors.
  44.