Difference between array and sequence

2 posts / 0 new
Last post
Ucf bader's picture
Offline
Last seen: 9 months 2 days ago
Joined: 03/10/2021
Posts: 2
Difference between array and sequence

Hello,
I was wondering what is the difference between a sequence (FooSeq) and array, in terms of:
1) order of elements.

2) accessing elements.

3) transmission of data (is only valid elements of a sequence being transmitted?)

4) Which one is a better resolution if  the max size is known.

thanks a lot..

Keywords:
Howard's picture
Offline
Last seen: 1 day 21 hours ago
Joined: 11/29/2012
Posts: 571

The fundmental difference is that an array is a fixed-length list of elements whereas a sequence is a variable-length list of elements.

I'm not clear what you mean by order.  Elements in both arrays and sequences are ordered and accessible by index.

As for accessing elements, this depends greatly on which language binding you're asking about.  In plain C, an array is just a block of memory that you access through standard pointers or using the array [] notation.  Whereas, you have to use type-specific functions to set and get elements of sequences.

In C++, since sequences are classes, override functions are provided so that sequences can be access similar to arrays using [] notation.  In the HTML API documentation, you can find all of the access methods for a FooSeq for different languages, e.g.

https://community.rti.com/static/documentation/connext-dds/7.1.0/doc/api/connext_dds/api_c/group__DDSSequenceModule.html

https://community.rti.com/static/documentation/connext-dds/7.1.0/doc/api/connext_dds/api_cpp/structFooSeq.html

https://community.rti.com/static/documentation/connext-dds/7.1.0/doc/api/connext_dds/api_cpp2/classrti_1_1core_1_1bounded__sequence.html

For sending data, there is no concept of "valid" elements for an array.  All of the elements of a fixed sized arrays are always sent.  For a sequence, the sequence has a length that reflect the number of valid elements in the sequence.  You can modify the length to be smaller or larger as the sequence shrinks or grows.  Only the valid elements of a sequence are sent.

If your data set is variable in size, then you should use a sequence.  If the data set is fixed in size then use an array.