Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6794575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:14:18+00:00 2026-05-26T18:14:18+00:00

Is it valid to develop a DLL in C++ that returns boost shared pointers

  • 0

Is it valid to develop a DLL in C++ that returns boost shared pointers and uses them as parameters?

So, is it ok to export functions like this?

1.) boost::shared_ptr<Connection> startConnection();
2.) void sendToConnection(boost::shared_ptr<Connection> conn, byte* data, int len);

In special: Does the reference count work across DLL boundaries or would the requirement be that exe and dll use the same runtime?

The intention is to overcome the problems with object ownership. So the object gets deleted when both dll and exe don’t reference it any more.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:14:18+00:00Added an answer on May 26, 2026 at 6:14 pm

    According to Scott Meyers in Effective C++ (3rd Edition), shared_ptrs are safe across dll boundaries. The shared_ptr object keeps a pointer to the destructor from the dll that created it.

    In his book in Item 18 he states, “An especially nice feature of
    tr1::shared_ptr is that it automatically uses its per-pointer deleter
    to eliminate another potential client error, the “cross-DLL problem.”
    This problem crops up when an object is created using new in one
    dynamically linked library (DLL) but is deleted in a different DLL. On
    many platforms, such cross-DLL new/delete pairs lead to runtime
    errors. tr1::shared_ptr avoid the problem, because its default deleter
    uses delete from the same DLL where the tr1::shared_ptr is created.”

    Tim Lesher has an interesting gotcha to watch for, though, that he mentions here. You need to make sure that the DLL that created the shared_ptr isn’t unloaded before the shared_ptr finally goes out of scope. I would say that in most cases this isn’t something you have to watch for, but if you’re creating dlls that will be loosely coupled then I would recommend against using a shared_ptr.

    Another potential downside is making sure both sides are created with compatible versions of the boost library. Boost’s shared_ptr has been stable for a long while. At least since 1.34 it’s been tr1 compatible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using VS 2008 to develop an application that uses a .dll with
I would like to develop a small notifications application for Windows in .NET that
Is this valid and correct? RewriteRule ^myOldPage.html$ /index.php#info [R] I'm specifically interested about the
(clickable) Mainad has a valid height and width, however it isn't shown like subad1/subad2.
Is this valid dbo.dbo , if so what does it mean? I have spoted
I'm trying to develop a schema that will validate some existing XML files I've
All valid words that must have even number of a's or even number of
I have a device and the drivers for this device. What I would like
Like the title says,I would like to develop vala with vim.My productivity is badly
I'm going to develop a firefox extension which makes an XMLHttpRequest to this WebService.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.