Archived

This forum has been archived. Please start a new discussion on GitHub.

Smart Pointer for Sequences

I am trying to create a sequence in slice and be able to pass it around via smart pointer in c++. Am I correct in understanding that in order to do this I have to create a class (or ["cpp:class"] struct) wrapper to the sequence?

For instant i would have to:
sequence<string> DataSeq;

["cpp:class"] struct Data {
  DataSeq data;
}

interface Blah {
  void TransferData(Data data);
};
Is there no way to tell slice to create a sequence pointer?

Comments

  • benoit
    benoit Rennes, France
    Hi,

    Yes, it's correct. Why do you prefer passing the sequence with a smart pointer? I suppose it's to avoid the copy of the sequence?

    We could consider an alternative solution for this. Please contact us at info@zeroc.com if you have a commercial interest in such a feature.

    Cheers,
    Benoit.
  • Note that you could also implement a custom reference counted sequence type. See chapter 6.7.4 for details. If your custom sequence supports a range, you could also simply use the range mapping described in this chapter.

    The advantage of using a custom sequence type over using a class as a container is that you don't have to change the contract just to change the mapping.
  • benoit wrote: »
    Why do you prefer passing the sequence with a smart pointer? I suppose it's to avoid the copy of the sequence?

    That is exactly the case; to avoid copies. The next step is to put this data in a queue for a consumer later on. I suppose one could use zero copy to achive a very similar effect.

    If I understand it correctly, using zero copy would essentially move the copy of the data from the Ice internals (it having to creating a sequence) to the application (by copying the data into the queue). The end result is that there is still a copy, it's just being done in a different layer.

    marc wrote: »
    Note that you could also implement a custom reference counted sequence type.

    Great point. I hadn't considered that. If it weren't for the extra development time to take that route I probably would do it.


    Thanks for your comments.