home bbs files messages ]

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 33,077 of 33,346   
   Joshua Maurice to firstname.dot.lastn...@googlemail.c   
   Re: compilers, endianness and padding   
   22 May 13 22:38:23   
   
   b8bf9f0c   
   From: joshuamaurice@googlemail.com   
      
   On May 22, 9:27 am, Edward Rosten   
    wrote:   
   > let's say we have:   
   >   
   > struct Foo   
   > {   
   >         //some variables   
   >         double a_double;   
   >         //some more variables;   
   >   
   > };   
   >   
   > Let's say we have a pointer:   
   >   
   > double* d;   
   >   
   > One can imaging that the information already exists so that the system   
   > can know whether d points to the stack, the heap or some other area not   
   > covered by the other two. Let's assume that it points to the stack.   
   >   
   > If d points into the heap somewhere, it is not too much of a stretch to   
   > know where the beginning of the chunk of allocated memory is, and how big   
   > it is.   
      
   Actually, no. Suppose you ask for an array of double:   
       new double[7];   
   It's my understanding that a lot of heap implementations will not   
   return you /exactly/ an array of 7 doubles. It'll actually return to   
   you an array of 8 doubles. Nowhere will it track that it allocated   
   exactly 7. Instead, it keeps track that it gave you 8 or less, and it   
   doesn't care beyond that. It's actually quite possible for arrays of   
   POD types to not contain the actual size at all. It's sometimes more   
   efficient to not contain the exact size and instead round up to   
   multiples of 2 to use a small number of separate pools.   
      
      
   --   
         [ 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