Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!ut-emx!jamshid From: jamshid@ut-emx.uucp (Jamshid Afshar) Newsgroups: comp.lang.c++ Subject: Re: decalring large arrays Message-ID: <51091@ut-emx.uucp> Date: 24 Jun 91 05:51:49 GMT References: <285B94A3.25253@maccs.dcss.mcmaster.ca> <13324@aggie.ucdavis.edu> Followup-To: comp.lang.c++, comp.os.msdos.programmer Organization: The University of Texas at Austin; Austin, Texas Lines: 53 In article <13324@aggie.ucdavis.edu> fzjaffe@castor.ucdavis.edu (Rory Jaffe) writes: ... >Since this is the c++ group, here is a C++ suggestion: >I had a problem where I had to allocate a multidimensional large array. >I went crazy figuring out how to cast the pointer until I contacted >Borland: > >to allocate a 20 X 40 X 30 array: >float (* arrayname)[40][30] = new float[20][40][30] ; >to delete it >delete arrayname ; // BC++ doesn't care to be told it's an array here While this deletion works for objects without destructors, you should generally tell operator delete() when you are deleting an array, otherwise it doesn't know to call the destructor for anything but the first object. The syntax is: delete [ARRAY_SIZE] p; In 2.1 compilers (not BC++) you are no longer required to give the size since the implementation is required to maintain that information: delete [] p; This makes me wonder, why then do you have to tell delete() that it's deleting an array?? >... >If the array is greater than 64K, just cast the pointer to huge in the >above example. **DO NOT DO THIS**. operator new() takes a parameter of size_t, which Borland C++ defines as an unsigned int (even in the huge model). This means you can never allocate more than 64K with operator new(). In general, casting, or even using, 'far', 'near' and 'huge' in MS-DOS is just asking for trouble. Save yourself alot of grief and just use the large model and don't put these (non-portable) keywords in your code. If at all possible, don't use objects or arrays larger than 64K since they require you mess with huge pointers and farmalloc/free. There is a Turbo/Borland C++ mailing list. To subscribe, send mail to listserv@ucf1vm.cc.ucf.edu OR listserv@ucf1vm.bitnet Containing the line subscribe tcplus-l Your Name There is also a Turbo/Borland C++ bug list available from sun.soe.clarkson.edu [128.153.12.3] in the file ~ftp/pub/Turbo-C++/bug-report. Jamshid Afshar jamshid@emx.utexas.edu