Coder Social home page Coder Social logo

Comments (2)

jonathan-beard avatar jonathan-beard commented on May 16, 2024

So the issue boils down to the way shared pointers are copied, this fixes the issue...but without calling the constructor each time for the FIFO element it'll segfault. The relevant section of the C++ memory header file is attached via screen shot below. Interestingly running this inside a debugger magically fixes the issues.
screen shot 2015-09-25 at 8 17 05 pm

#include
#include
#include

int
main( int argc, char **argv )
{
std::shared_ptr< std::uint32_t > x = std::make_shared< std::uint32_t >();
*x = 100;

char data = (char) malloc( sizeof( char ) * sizeof( x ) );
#ifdef REPLICATE
auto test( reinterpret_cast< std::shared_ptr< std::uint32_t > >( data ) );
#else //FIX
auto test( new ( data ) std::shared_ptr< std::uint32_t >() );
#endif
/
* should segfault **/
*test = x;
std::cout << x.use_count() << "\n";
std::cout << test->use_count() << "\n";
return( EXIT_SUCCESS );
}

from raftlib.

jonathan-beard avatar jonathan-beard commented on May 16, 2024

Solution to this bug is to use a template function specialization with std::enable_if for object types so that non POD will have the default in-place constructor called to initialize any data members that could potentially be needed....but that's just a first take something far simpler should fix this......

from raftlib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.