Public Member Functions | |
final Class | getElementType () |
abstract void | add (int index, Object element) |
Inserts the specified element at the specified position in this sequence. | |
void | loan (Object buffer, int new_length) |
Loan a contiguous buffer to this sequence. | |
void | unloan () |
Return the loaned buffer in the sequence and set the maximum to 0. | |
final boolean | hasOwnership () |
Return the value of the owned flag. | |
final void | clear () |
final void | setSize (int newSize) |
final int | size () |
final Object | copy_from (Object src) |
final Class getElementType | ( | ) |
Reimplemented from AbstractSequence.
abstract void add | ( | int | index, | |
Object | element | |||
) | [pure virtual] |
Inserts the specified element at the specified position in this sequence.
Reimplemented from AbstractSequence.
Implemented in BooleanSeq, ByteSeq, CharSeq, DoubleSeq, FloatSeq, IntSeq, LongSeq, and ShortSeq.
void loan | ( | Object | buffer, | |
int | new_length | |||
) |
Loan a contiguous buffer to this sequence.
This operation changes the owned
flag of the sequence to false and also sets the underlying buffer used by the sequence. See the user's manual for more information about sequences and memory ownership.
Use this method if you want to manage the memory used by the sequence yourself. You must provide an array of elements and integers indicating how many elements are allocated in that array (i.e. the maximum) and how many elements are valid (i.e. the length). The sequence will subsequently use the memory you provide and will not permit it to be freed by a call to Sequence.setMaximum.
By default, a sequence you create owns its memory unless you explicitly loan memory of your own to it. In a very few cases, RTI Connext will return a sequence to you that has a loan; those cases are documented as such. For example, if you call com.rti.dds.topic.example.FooDataReader.read or com.rti.dds.topic.example.FooDataReader.take and pass in sequences with no loan and no memory allocated, RTI Connext will loan memory to your sequences which must be unloaned with com.rti.dds.topic.example.FooDataReader.return_loan. See the documentation of those methods for more information.
AbstractPrimitiveSequence.hasOwnership == true; i.e. the sequence does not already have an outstanding loan
AbstractPrimitiveSequence.hasOwnership == false
Sequence.size() == new_length
Sequence.getMaximum == new_max
buffer | The new buffer that the sequence will use. Must point to enough memory to hold new_max elements of type Foo. It may be NULL if new_max == 0. | |
new_length | The desired new length for the sequence. |
buffer
is successfully loaned to this sequence or false otherwise. Failure only occurs due to failing to meet the pre-conditions. Upon failure the sequence remains unmodified. void unloan | ( | ) |
Return the loaned buffer in the sequence and set the maximum to 0.
This method affects only the state of this sequence; it does not change the contents of the buffer in any way.
Only the user who originally loaned a buffer should return that loan, as the user may have dependencies on that memory known only to them. Unloaning someone else's buffer may cause unspecified problems. For example, suppose a sequence is loaning memory from a custom memory pool. A user of the sequence likely has no way to release the memory back into the pool, so unloaning the sequence buffer would result in a resource leak. If the user were to then re-loan a different buffer, the original creator of the sequence would have no way to discover, when freeing the sequence, that the loan no longer referred to its own memory and would thus not free the user's memory properly, exacerbating the situation and leading to undefined behavior.
maximum == 0
final boolean hasOwnership | ( | ) |
Return the value of the owned flag.
final void clear | ( | ) |
Set the logical size of this sequence to zero. This method does not generate any garbage for collection.
final void setSize | ( | int | newSize | ) |
Set the logical size of this sequence to the given value.
newSize | the new logical size of this sequence; it must be less than or equal to the maximum allocated length of the underlying array. |
IndexOutOfBoundsException | if the new size is less than zero or greater than the allocated length of the array. |
final int size | ( | ) |
The logical size of this sequence.
final Object copy_from | ( | Object | src | ) |
Implementation of the Copyable
interface.
src | An AbstractPrimitiveSequence which contains the data to be copied. |
this
NullPointerException | If src is null. | |
ClassCastException | If src is not a Sequence OR if one of the objects contained in the Sequence is not of the expected type. |
Implements Copyable.