Difference between array and sequence

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

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..

Howard's picture
Last seen: 3 days 2 hours ago
Joined: 11/29/2012
Posts: 545

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.




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.