Thread: goto

  1. #31
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Quote Originally Posted by Bubba View Post
    Another issue I have with boost has to do with the templates. I realize the only way to create a library such as boost is to use templates but this makes using them in projects with multiple DLLs a major issue. You can't return boost::weak_ptr's or boost::shared_ptr's across a DLL boundary. What you end up with is a system which resides in a DLL which either hands out handles to the objects or hands out raw pointers to them. Handing out raw pointers here is a very bad idea indeed since if delete is called on said pointers and those pointers were created in the DLL, the CRT of the caller will be pretty much hosed. So you will end up passing out handles to boost::shared_ptr's that really do nothing. Since you are using handles you might as well store raw pointers inside the container and forego boost altogether. Boost is fine when used in the same module but cannot be used effectively across multiple modules even using the PIMPL idiom - which you must do or you will get a warning similar to: clients of xxx must have a dll-interface to access templated member<X> Of course this type of system could be re-factored so it actually factories out the object in the CRT of the caller instead of the DLL but it's just an illustration of some issues.
    Are you sure about that? If I remember correctly, the only issue with sharing boost smart pointers across DLLs is when the DLL that created the underlying object is unloaded before the object is destructed.
    bit∙hub [bit-huhb] n. A source and destination for information.

  2. #32
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by bithub View Post
    Are you sure about that? If I remember correctly, the only issue with sharing boost smart pointers across DLLs is when the DLL that created the underlying object is unloaded before the object is destructed.
    I think the problem is that each DLL has its own heap, which means if the ref count goes to zero in a different module it will attempt to delete the object (and the refcount, which is tracked separately) from the wrong heap.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #33
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Quote Originally Posted by brewbuck View Post
    I think the problem is that each DLL has its own heap, which means if the ref count goes to zero in a different module it will attempt to delete the object (and the refcount, which is tracked separately) from the wrong heap.
    But how is that different than the following (which you see in libraries all the time).
    Code:
    // Caller is responsible for freeing up memory
    char* some_dll_function(void)
    {
        return malloc(100);
    }
    bit∙hub [bit-huhb] n. A source and destination for information.

  4. #34
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by bithub View Post
    But how is that different than the following (which you see in libraries all the time).
    Code:
    // Caller is responsible for freeing up memory
    char* some_dll_function(void)
    {
        return malloc(100);
    }
    I dunno. It's just a wild guess. I'm probably wrong.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. add,view=ok, search,edit got error... help!
    By private0430 in forum C Programming
    Replies: 4
    Last Post: 09-27-2009, 01:36 PM
  2. temperature sensors
    By danko in forum C Programming
    Replies: 22
    Last Post: 07-10-2007, 07:26 PM
  3. Does goto have a glitch or...?
    By Blackroot in forum C++ Programming
    Replies: 9
    Last Post: 02-18-2006, 10:40 AM
  4. helpppp
    By The Brain in forum C Programming
    Replies: 1
    Last Post: 07-27-2005, 07:05 PM
  5. Need some help with a basic tic tac toe game
    By darkshadow in forum C Programming
    Replies: 1
    Last Post: 05-12-2002, 04:21 PM