[omniORB] Allocation of memory for sequence "vars"

Frederic Prin frederic.prin at silvaco.com
Tue Sep 21 20:04:35 BST 2004


Yes, what about testing

if( me == SEQ::ABCseq::_nil() )

Or 

If ( CORBA::is_nil(me) )

HIH

Fred

-----Original Message-----
From: omniorb-list-bounces at omniorb-support.com
[mailto:omniorb-list-bounces at omniorb-support.com] On Behalf Of Clarke
Brunt
Sent: mardi 21 septembre 2004 18:30
To: omniorb-list at omniorb-support.com
Subject: Re: [omniORB] Allocation of memory for sequence "vars"


From: "Green, Wallace J" <wallace.j.green at boeing.com>

>I have a very simple sequence that I am allocating and would like to 
>check that the allocation was successful.
>
>The IDL is :
>
>    interface SEQ {
>
>        enum ABC { want, more };
>        typedef sequence<ABC> ABCseq;
>    };
>
>And the code (C++) I wish to convert is:
>
>   SEQ::ABCseq_var me = new SEQ::ABCseq();
>    if(me == NULL) printf("ERROR\n");
>
>When I compile this, using OMNI, I get an error on the "me == NULL" 
>test to the effect that no such comparison is available.
>
>So, under OMNI, what is the appropraite way to verify that the 
>allocation via the "new" was successful?

I'm never sure how this is intended to be handled either. I've sometimes
wanted to use a _var type, and to be able to check whether it currently
does or doesn't contain anything.

Obviously, you can check the allocation before assigning to the _var

SEQ::ABSseq *pme = new SEQ::ABCseq;
if (pme == NULL) error...
SEQ::ABCseq_var me = pme;

but that doesn't seem very tidy.

Or you can get at the contained pointer using operator->(), i.e. if
(pme.operator->() == NULL) error...

but the spec. seems to say that you aren't strictly allowed to call
operator-> before assigning a valid pointer. Then again, perhaps NULL 
operator-> _is_ a
valid pointer, albeit to nowhere. Indeed I might consider assigning a
NULL to the _var to 'empty it out'. The _var also probably has a
conversion operator to 'const ABCseq&' for use as an 'in' arg. Its in()
method will produce the same thing. So you could have something equally
horrid-looking like

if (&me.in() == NULL) error...

And, remember that although you might succeed in allocating the
sequence, it still has a length of zero (with the default constructor).
If you want to check every memory allocation, you're going to have to
worry about what happens when you e.g. call length(n) on it.

So, what does anyone else think? What _are_ you supposed to do?

Clarke Brunt, Pincipal Software Engineer, Yeoman Navigation


_______________________________________________
omniORB-list mailing list
omniORB-list at omniorb-support.com
http://www.omniorb-support.com/mailman/listinfo/omniorb-list




More information about the omniORB-list mailing list