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,431 of 33,346   
   =?ISO-8859-1?Q?Daniel_Kr=FCgler?= to All   
   Re: question: shared pointers with custo   
   29 Aug 11 05:32:21   
   
   beb187d9   
   From: daniel.kruegler@googlemail.com   
      
   Am 28.08.2011 20:17, schrieb Andrew:   
   > 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).   
   >   
   > 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*).   
      
   At this point I'm not sure whether I understand your approach correctly.   
   What does "make the uuid_t pointer a shared pointer" mean precisely?   
      
   > 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'   
   >   
   > I know this is boost but surely the same applies for the equivalent   
   > smart pointers in TR1.   
   >   
   > Can anyone comment on this please?   
      
   You need to provide at least the minimum code necessary to reproduce the   
   problem. I think this should work, at least if I understand your idea   
   correctly. E.g. using the current boost library 1.47.0 the following   
   code compiles successfully with gcc 4.7.0:   
      
   extern "C" {   
      
   struct uuid_t;   
      
   uuid_t* uuid_create();   
      
   void uuid_destroy(uuid_t*);   
      
   }   
      
   #include    
      
   int main()   
   {   
      boost::shared_ptr pu(uuid_create(), uuid_destroy);   
   }   
      
   Looking at the boost documentation (or for comparison: The new C++11   
   standard specification of std::shared_ptr), there is no requirement that   
   uuid_t must be complete, when shared_ptr is created with the   
   provided deleter.   
      
   HTH & Greetings from Bremen,   
      
   Daniel Krügler   
      
      
   --   
         [ 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