home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!microsoft!hexnut!jimad
- From: jimad@microsoft.com (Jim Adcock)
- Subject: Re: Allocating arrays larger than 64K with new?
- Message-ID: <1992Aug17.225946.12583@microsoft.com>
- Date: 17 Aug 92 22:59:46 GMT
- Organization: Microsoft Corporation
- References: <1992Aug9.152253.11345@newshub.sdsu.edu>
- Lines: 33
-
- In article <1992Aug9.152253.11345@newshub.sdsu.edu> add@newshub.sdsu.edu (James D. Murray) writes:
- >
- >Just how does one use 'new' to allocate an array larger than 'size_t'
- >bytes in size?
-
- Two ideas. This first one is what I prefer, namely write a "smart array":
-
- class HugeArray
- {
- void* phugearray;
- HugeArray(long size) { phugearray = huge_alloc(size); }
- ....
- };
-
- main()
- {
- HugeArray* p = new HugeArray(10000000);
- }
-
-
- Second Idea: declare a custom new with a "placement" parameter that specifies
- the number of elements:
-
- void* operator new(size_t size, long nelements)
- { return huge_alloc(size*nelements); }
-
- main()
- {
- double* hugearray = new(1000000) double;
- }
-
- This second approach has the disadvantage of not calling the "right"
- number of constructors, when used with classes that have constructors.
-