Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost-users Digest, Vol 2718, Issue 1
From: Mupparthy Ravindranath (rv_nath_at_[hidden])
Date: 2011-05-10 07:02:28


Actually, My intention is to pass a shared_ptr, as against a raw ptr.  The purpose is that after execting the callback, the shared_ptr can go out of scope, and ensure object deletion on its own, without having to call an explicit delete. So, I really wanted to pass a shared_ptr to the callback fn, as a void*. The reason behind this is... - i have a 3rd party timer engine, which accepts a callback function and callback args. - On timer expiry, it calls my regd callback implmentation, along with the args passed in its start_timer function. - Earlier, I was passing an object* to the callback args of the timer. - If the timer event fires, my callback impl gets called, and I get a chance to do a "delete", which is fine. - In some cases, I have to cancel / stop the timer.  And then since, my callback doesn't fire, I have no way to delete the obj*, and results in a memory leak. So, I wanted to pass a shared_ptr itself as the callback argument for my 3rd party timer. So that, even if timer doesn't fire, my object won't leak. regards, RV ________________________________ From: "boost-users-request_at_[hidden]" <boost-users-request_at_[hidden]> To: boost-users_at_[hidden] Sent: Tuesday, 10 May 2011 4:15 PM Subject: Boost-users Digest, Vol 2718, Issue 1 Send Boost-users mailing list submissions to     boost-users_at_[hidden] To subscribe or unsubscribe via the World Wide Web, visit     http://lists.boost.org/mailman/listinfo.cgi/boost-users or, via email, send a message with subject or body 'help' to     boost-users-request_at_[hidden] You can reach the person managing the list at     boost-users-owner_at_[hidden] When replying, please edit your Subject line so it is more specific than "Re: Contents of Boost-users digest..." Today's Topics:   1. Re: Error: guid_defined is not       templateBOOST_CLASS_EXPORT_GUID (Robert Ramey)   2. Re: [Boost][program-options] Original position of an    argument       in command-line. (Vladimir Prus)   3. How to cast a boost::shared_ptr to void* (Mupparthy Ravindranath)   4. Re: How to cast a boost::shared_ptr to void* (Robert Jones)   5. Re: How to cast a boost::shared_ptr to void* (michi7x7)   6. Re: How to cast a boost::shared_ptr to void*       (Mupparthy Ravindranath)   7. Re: How to cast a boost::shared_ptr to void* (Robert Jones)   8. Re: [Boost][program-options] Original position of an argument       in command-line. (Germ?n Diago) ---------------------------------------------------------------------- Message: 1 Date: Mon, 9 May 2011 21:57:06 -0800 From: "Robert Ramey" <ramey_at_[hidden]> To: boost-users_at_[hidden] Subject: Re: [Boost-users] Error: guid_defined is not     templateBOOST_CLASS_EXPORT_GUID Message-ID: <iqagie$sbh$1_at_[hidden]> Jari wrote: > Hi > I am using boost serialization and it was working fine (save load > works) but then I tried using BOOST_CLASS_EXPORT_GUID and get weird > error. > > The line that gives the error is this: > > BOOST_CLASS_EXPORT_GUID( Bakery, "Bakery") > > > (I put the code in Cpp to avoid any problems with headers.) > > > And this is the full Visual studio express 2010 error: > > 2>E:\boost_1_46_1\boost/archive/detail/check.hpp(162): error C2338: > typex::value ... what does the code look like at line 162 of check.hpp ? Robert Ramey ------------------------------ Message: 2 Date: Tue, 10 May 2011 10:45:04 +0400 From: Vladimir Prus <vladimir_at_[hidden]> To: boost-users_at_[hidden] Subject: Re: [Boost-users] [Boost][program-options] Original position     of an    argument in command-line. Message-ID: <iqamtg$nvf$1_at_[hidden]> Content-Type: text/plain; charset="UTF-8" Germ?n Diago wrote: > Hi all. I have a question regarding boost.program_options. > > I want to parse a command-line but I want to know the order in which > each option appeared in the > command line. Is this possible? Thanks in advance. parse_command_line returns vector< basic_option<charT> >, which are in the order of occurence. This is a point where you can do logic based on the order. variables_map does not store order information. HTH, -- Vladimir Prus Mentor Graphics +7 (812) 677-68-40 ------------------------------ Message: 3 Date: Tue, 10 May 2011 13:26:09 +0530 (IST) From: Mupparthy Ravindranath <rv_nath_at_[hidden]> To: "boost-users_at_[hidden]" <boost-users_at_[hidden]> Subject: [Boost-users] How to cast a boost::shared_ptr to void* Message-ID: <257490.53596.qm_at_[hidden]> Content-Type: text/plain; charset="iso-8859-1" Hi all, My requirement is to cast an object of type shared_ptr as void*, so that I can send it to a callback function that accepts a void*.? I cannot change callback the function signature because it is part of an existing legacy code. In the existing code, I am sending a raw object pointer (instead of shared_ptr).? Now, if I want to pass a shared_ptr, it won't compile because I cannot cast the shared ptr to void*.? Can anyone suggest some workaround for this.? I tried searching the mailing lists and internet, but not much luck. regards, RV -------------- next part -------------- HTML attachment scrubbed and removed ------------------------------ Message: 4 Date: Tue, 10 May 2011 09:01:05 +0100 From: Robert Jones <robertgbjones_at_[hidden]> To: boost-users_at_[hidden] Subject: Re: [Boost-users] How to cast a boost::shared_ptr to void* Message-ID: <BANLkTin7kyBhUYAVuhm5jWAX_goA3fUO0w_at_[hidden]> Content-Type: text/plain; charset="iso-8859-1" On Tue, May 10, 2011 at 8:56 AM, Mupparthy Ravindranath <rv_nath_at_[hidden]>wrote: > Hi all, > > My requirement is to cast an object of type shared_ptr as void*, so that I > can send it to a callback function that accepts a void*.  I cannot change > callback the function signature because it is part of an existing legacy > code. > > In the existing code, I am sending a raw object pointer (instead of > shared_ptr).  Now, if I want to pass a shared_ptr, it won't compile because > I cannot cast the shared ptr to void*. > > Can anyone suggest some workaround for this.  I tried searching the mailing > lists and internet, but not much luck. > > > struct X { }; boost::shared_ptr<X> p; void f( void *); f( p.get( ) ); should do it. But beware the pointee may be deleted if the last copy of the shared pointer goes out of scope, as the raw pointer won't have incremented the reference count. - Rob. -------------- next part -------------- HTML attachment scrubbed and removed ------------------------------ Message: 5 Date: Tue, 10 May 2011 10:06:40 +0200 From: michi7x7 <mailing-lists_at_[hidden]> To: boost-users_at_[hidden] Subject: Re: [Boost-users] How to cast a boost::shared_ptr to void* Message-ID: <4DC8F210.5090200_at_[hidden]> Content-Type: text/plain; charset=ISO-8859-1; format=flowed > Hi all, Hi > My requirement is to cast an object of type shared_ptr as void*, so that > I can send it to a callback function that accepts a void*. I cannot > change callback the function signature because it is part of an existing > legacy code. > You can get the raw-pointer using the member-function get() or the free function get_pointer (which should be prefered). smart_ptr<Class> ptr(new Class); Class * raw_ptr = get_pointer(ptr); You can cast the raw-pointer to void* of course. -- Best regards, michi7x7 ------------------------------ Message: 6 Date: Tue, 10 May 2011 14:24:26 +0530 (IST) From: Mupparthy Ravindranath <rv_nath_at_[hidden]> To: "boost-users_at_[hidden]" <boost-users_at_[hidden]> Subject: Re: [Boost-users] How to cast a boost::shared_ptr to void* Message-ID: <443447.3562.qm_at_[hidden]> Content-Type: text/plain; charset="iso-8859-1" Sorry for the spam.? I got the answer, how to do it. Ignore my previous mail. [quote] #include <boost/shared_ptr.hpp> #include <iostream> using namespace std; class A { ??? public: ??? void hello () { cout << "Hello, friends...!" << endl; } }; typedef boost::shared_ptr<A> APtr; void* callbk (void* o) { ??? APtr a = *static_cast<APtr*>(o); ??? a->hello(); } int main() { A* rawPtr = new A; boost::shared_ptr<A>sPtr(rawPtr); callbk((void*)&sPtr); return 0; } [/quote] warm regars, RV ________________________________ From: Mupparthy Ravindranath <rv_nath_at_[hidden]> To: "boost-users_at_[hidden]" <boost-users_at_[hidden]> Sent: Tuesday, 10 May 2011 1:26 PM Subject: How to cast a boost::shared_ptr to void* Hi all, My requirement is to cast an object of type shared_ptr as void*, so that I can send it to a callback function that accepts a void*.? I cannot change callback the function signature because it is part of an existing legacy code. In the existing code, I am sending a raw object pointer (instead of shared_ptr).? Now, if I want to pass a shared_ptr, it won't compile because I cannot cast the shared ptr to void*.? Can anyone suggest some workaround for this.? I tried searching the mailing lists and internet, but not much luck. regards, RV -------------- next part -------------- HTML attachment scrubbed and removed ------------------------------ Message: 7 Date: Tue, 10 May 2011 10:17:30 +0100 From: Robert Jones <robertgbjones_at_[hidden]> To: boost-users_at_[hidden] Subject: Re: [Boost-users] How to cast a boost::shared_ptr to void* Message-ID: <BANLkTikigCKTy4ROQD7wydmeNGuT4_e6Kw_at_[hidden]> Content-Type: text/plain; charset="iso-8859-1" On Tue, May 10, 2011 at 9:54 AM, Mupparthy Ravindranath <rv_nath_at_[hidden]>wrote: > Sorry for the spam.  I got the answer, how to do it. Ignore my previous > mail. > > [quote] > #include <boost/shared_ptr.hpp> > #include <iostream> > using namespace std; > > class A { >    public: >    void hello () { cout << "Hello, friends...!" << endl; } > }; > > typedef boost::shared_ptr<A> APtr; > > void* callbk (void* o) { >    APtr a = *static_cast<APtr*>(o); >    a->hello(); > } > > int main() { > A* rawPtr = new A; > boost::shared_ptr<A>sPtr(rawPtr); > callbk((void*)&sPtr); > return 0; > } > [/quote] > > Not like that! That passes the address of the shared pointer, not the address of your new'd object. If it works it's by luck! - R. -------------- next part -------------- HTML attachment scrubbed and removed ------------------------------ Message: 8 Date: Tue, 10 May 2011 12:45:03 +0200 From: Germ?n Diago <germandiago_at_[hidden]> To: boost-users_at_[hidden] Subject: Re: [Boost-users] [Boost][program-options] Original position     of an argument in command-line. Message-ID: <BANLkTinL0zUharoHtZJeOFxz6D=eo6_6WQ_at_[hidden]> Content-Type: text/plain; charset=ISO-8859-1 > parse_command_line returns vector< basic_option<charT> >, which > are in the order of occurence. This is a point where you can do > logic based on the order. variables_map does not store order > information. Thanks! Very useful! ------------------------------ _______________________________________________ Boost-users mailing list Boost-users_at_[hidden] http://lists.boost.org/mailman/listinfo.cgi/boost-users End of Boost-users Digest, Vol 2718, Issue 1 ********************************************



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net