Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Scope of a sequence - REALLY NEED HELP

Scope of a sequence - REALLY NEED HELP

Scope of a sequence - REALLY NEED HELP

Hi everyone,

I currently have an object that has a sequence of
pointers to another object. Using methods I created I
can insert the pointers into the sequence which is
basically easy. When I call the function of the object
that returns the sequence (so that I can iterate
through it and display it) all goes well. The problem
is that whenever I call it a second time nothing

Is it correct to assume that once you use the sequence
it immediately goes out of scope? If so then does that
mean that the values which I filled the sequence with
no longer exist? If this is the case then how can I
keep those values and stop the ORB from erasing the
data within the sequence? I think I read somewhere
that you can initialise a sequence with something like
Seq(len,max,buffer,...) but I can't fully remember.
Can this help prevent the ORB from erasing the data so
that it's solely under my control? Has anyone got any
good examples of this?

Your help is very needed and will be much appreciated.


Replies continue below

Recommended for you

RE: Scope of a sequence - REALLY NEED HELP

hi johnstv4

for the specs of the sequence type in IDL i can point you  the "IDL-C++" mapping, published by OMG as formal/99-07-41.pdf.
Anyway, the return type is an out type, which when goes out of scope can destroy all of its data, depending on the value of the release parameter in the declaration of the type. You can test this value with the accessor function release().
There are differences also depending if the return type is declared as the output of your function, or as an out parameter, or as an inout one.
As a rule of thumb, the responsibility for storage allocation is on the stubs for return types and for out parameters, and on the caller if it is an inout one.
Which means that if you want to retain previous data, you must use inout parameter.

Hope it helps

RE: Scope of a sequence - REALLY NEED HELP

Thanks domenico,

Your advise was very valuable. i'm having some other trouble now regarding sequences. I'm removing elements from sequences using the following server code:

void Customer_impl::remove_account(Account_ptr ptrAccount)
    CORBA::ULong index = 0;

    // First we need to find out at which index the Account is held within the sequence
    for (CORBA::ULong i = 0; i < CustomerAccountList->length(); i++)
        if (CustomerAccountList[i] == ptrAccount)
            index = i;

    // Now that we know where abouts within the sequence the Account is we can remove it
    for (CORBA::ULong j = index; j < CustomerAccountList->length() - 1; j++)
        CustomerAccountList[j] = CustomerAccountList[j + 1];

    CustomerAccountList->length(CustomerAccountList->length() - 1);

    cout << "Length is " << CustomerAccountList->length() << "\n";

At first all seems fine when the client is removing accounts from the sequence. But for some reason the accounts displayed on the client are sometimes incorrect? For example, when I remove the first account of the sequence it seems to remove the ones that come after it? Could you help me and tell me how I should properly implement code which removes entries from the sequence? Your help is very much appreciated.



Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close