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 31,598 of 33,346   
   red floyd to Shan   
   Re: Memory deallocation   
   01 Nov 11 12:35:38   
   
   795cda60   
   From: no.spam.here@its.invalid   
      
   On 11/1/2011 3:57 AM, Shan wrote:   
   > FieldValues = new vector();   
   >   
   >   
   >    I have the above FieldValues in a class as private member. How should   
   > I deallocate the memory allocated by this vector. Also I am populating   
   > the vector with  dynamically allocated. I want make sure that   
   > char* memory also deallocated when I destroy the instance of the   
   > class.   
   >   
   >   
   In addition to what has been said... Why are you dynamically allocating   
   the vector to begin with?  Unless you populate it, vector takes up   
   very little space.   
      
   Better would be  vector FieldValues;   
      
   Also, is your char* data string data, or is it actual arrays of   
   characters?   
      
   In the first case, a better usage would be vector   
   In the second case, better would be vector >;   
      
   Assuming you don't dynamically allocate the vector (as in   
   my first point), then either one of these two solutions   
   provides RAII garbage collection, and then you don't have   
   to worry about cleaning up.   
      
      
   --   
         [ 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