Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c++.moderated    |    Moderated discussion of C++ superhackery    |    33,346 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 32,094 of 33,346    |
|    Francis Glassborow to Thomas Mang    |
|    Re: allocate memory 'inside' POD    |
|    04 Apr 12 15:37:31    |
   
   From: francis.glassborow@btinternet.com   
      
   On 04/04/2012 07:24, Thomas Mang wrote:   
   > On 03/04/2012 22:40, AnonMail2005@gmail.com wrote:   
   >   
   >>   
   >> This sounds like it will be impossible to maintain.   
   >   
   > Well there would be, of course, a fancy C++ interface which wraps all   
   > that stuff and which makes use (relatively) easy and save on the C++   
   > side. But the core must be developed given the restrictions as it will   
   > passed around in the heterogeneous environemnt.   
   >   
   >>   
   >> How big can the array of doubles be? I would just make the array   
   >> fixed at some maximum size and have the integer specify the number of   
   >> actual values populated.   
   >   
   > Not possible; the system is ways too large to do it in a "safe maximum"   
   > manner (applications will spand orders of magnitude).   
   >   
   > Thomas   
   >   
   >   
   OK so here is a sketch of an idea that might meet your needs.   
   struct array {   
    unsigned long elements;   
    double first;   
   };   
      
   Now use operator new to obtain sufficient memory for and instance of   
   array + space for the required number of doubles.   
      
   Next use placement new (the standard version) to create an instance of   
   array at the start of the memory block. Then get the address of first   
   and use that with placement new[] to create an array of doubles of the   
   required size. Note that a simple variable is required (IIRC) to be   
   equivalent to an array of size 1.   
      
      
   --   
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca