Scope of data in IccBuf reference returned from 'read' methods

Many of the subclasses of IccResource have 'read' methods that return const IccBuf references; for example, IccFile::readRecord , IccTempStore::readItem and IccTerminal::receive.

Care should be taken if you choose to maintain a reference to the IccBuf object, rather than copy the data from the IccBuf reference into your own IccBuf object. For example, consider the following
 IccBuf buf(50);
IccTempStore store("TEMPSTOR");
buf = store.readNextItem();
Here, the data in the IccBuf reference returned from IccTempStore::readNextItem is immediately copied into the application's own IccBuf object, so it does not matter if the data is later invalidated. However, the application might look like this
 IccTempStore store("TEMPSTOR");
const IccBuf& buf = store.readNextItem();

Here, the IccBuf reference returned from IccTempStore::readNextItem is not copied into the application's own storage and care must therefore be taken.

Note: You are recommended not to use this style of programming to avoid using a reference to an IccBuf object that does not contain valid data.
The returned IccBuf reference typically contains valid data until one of the following conditions is met:
  • Another 'read' method is invoked on the IccResource object (for example, another readNextItem or readItem method in the example).
  • The resource updates are committed (see method IccTask::commitUOW).
  • The task ends (normally or abnormally).


dfhal0h.html | Timestamp icon Last updated: Monday, 5 June 2017