[Ace-users] [tao-users] Is strdup required for return and out parameters
Douglas C. Schmidt
schmidt at dre.vanderbilt.edu
Fri Oct 19 05:00:46 CDT 2007
Hi Vikram,
Please follow the earlier advice and read the book "Advanced CORBA
Programming with C++" or "CORBA Explained Simply" for information on how
to use CORBA/C++ memory mapping properly. You can download the latter
book at
http://www.ciaranmchale.com/download/corba-explained-simply.pdf
Thanks,
Doug
> thank you for your replies.
> My original question was a bit different. i just want to confirm few things.
> as i said i have a DS which is passed as in parameter to method1 and out parameter in method2.
> Now there is s string field in the above DS which is mapped to String_manager.
> Now String_manager makes copy if we assign a const char* to it and does not make copy if
> we assign char* to it.
>
> Scenario 1. Now consider a case of method1. In this method if i assign a const char * to it then at the return from this
> method it will be freed. But if i assign char * then i may be in trouble. Because i may have assigned a
> string whose ownership was with someone else also.
>
> so to avoid such problems if i always do CORBA::string_dup for all the string fields will it cause any
> memory leak on CORBA client?
>
> Scenario 2. Now consider a case of method2. Here CORBA frees memory of out parameters (on Server side) after return
> from the method. So here its always better to do CORBA::string_dup.
> So i don't think there is any issue with this.
>
> Please comment on both the scenarios.
> Thank you.
>
> On 18 Oct 2007 17:02:17 +0200, Tommy Persson <tpe at ida.liu.se> wrote:
>
> Chris Cleeland < cleeland at ociweb.com> writes:
>
> > On Oct 18, 2007, at 7:40 AM, Vikram Karandikar wrote:
> >
> > > So either i should use strdup or CORBA::string_dup but stick to one.
> > > am i right?
> >
> > No, you should use only CORBA::string_dup() when duplicating CORBA
> > strings.
> >
> > Consult the Henning & Vinoski book suggested by Christian for details
> > and further information.
>
> I have read the book but totally misssed this. So could you indicate
> where it is discussed or why?
>
> In page 147 i says that
>
> char * p = CORBA::string_dup ("Hello");
>
> is correct code but "Hello" is not a CORBA::String. And I routinely do
> things like
>
> return CORBA::string_dup (res.c_str());
>
> So what is the problem with this construction?
>
> --
> /Tommy Persson
>
> _______________________________________________
> tao-users mailing list
> tao-users at mail.cse.wustl.edu
> http://mail.cse.wustl.edu/mailman/listinfo/tao-users
>
> --
> "There is no substitute for intelligence, experience, common sense, and good taste." - Bjarne Stroustrup
>
> - Vikram Karandikar
>
> _______________________________________________
> tao-users mailing list
> tao-users at mail.cse.wustl.edu
> http://mail.cse.wustl.edu/mailman/listinfo/tao-users
More information about the Ace-users
mailing list