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,432 of 33,346   
   Ulrich Eckhardt to Andrew   
   Re: question: shared pointers with custo   
   29 Aug 11 05:34:57   
   
   beb187d9   
   From: ulrich.eckhardt@dominolaser.com   
      
   Andrew wrote:   
   > I am writing a uuid class. It uses the native WIN32 API on windoze and   
   > uses a C uuid library otherwise. The uuid library header file fwd   
   > declares uuid_t and all the functions take a pointer to uuid_t. Hence   
   > uuid_t does not need to be defined, a fwd-declare is enough. The   
   > details are in the C implementation, the header file is hiding the   
   > implementation details (quite right too).   
      
   I'm not quite sure whether it is the C library that you are talking about or   
   the one you intend to write.   
      
      
   > The problem I have is that my uuid objects need to exist inside STL   
   > containers so they will be copied. I need to ensure that the memory   
   > allocated by the uuid library is only deallocated once. So I thought I   
   > would be able to make the uuid_t pointer a shared pointer with a   
   > custom deleter. The custom deleter uses uuid_destroy(uuid_t*).   
      
   Again, at what level are you arguing here? If the uuid_t is from the library   
   which you are wrapping with a C++ class, all that should be necessary is   
   that you properly implement constructor, copy constructor, assignment   
   operator and destructor.   
      
   That said, you _can_ use shared_ptr with incomplete types.   
      
      
   > However, I am getting a massive compilation error message during the   
   > parsing of some custom deleter header file that is getting pulled in   
   > somehow. The error message makes me think that the use of a custom   
   > deleter requires that the type be fully known. The error message   
   > includes this:   
   >   
   > /usr/local/boost/include/boost/checked_delete.hpp:32: error: invalid   
   > application of 'sizeof' to incomplete type 'uuid_t'   
      
   If I remember that code correctly, the default deleter (which just invokes   
   "delete" on the pointer) first uses sizeof in order to make sure the type is   
   fully defined. I also know that I have used shared_ptr with a custom   
   deleter, and that works without warnings.   
      
      
   Summary: You intend right, but do something wrong. Show an example!   
      
   Uli   
      
      
   --   
   Domino Laser GmbH   
   Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932   
      
      
         [ 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