HP Integrity NonStop J-Series User Manual
Page 205

RWCollectable
:
Rwvistream& operator>>(RWvistream&, RWCollectable&);
instead of to a pointer to a reference to an
RWCollectable
:
Rwvistream& operator>>(RWvistream&, RWCollectable*&);
The collection was allocated on the stack:
RWpistream istr(cin);
RWOrdered collection2;
istr >> collection2;
...
collection2.clearAndDestroy();
instead of having operator>>(RWvistream&,RWCollectable*&) allocate the memory for the
collection:
RWpistream istr(cin);
RWOrdered* pCollection2;
istr >> pCollection2;
...
collection->clearAndDestroy();
delete pCollection2;
Why make this choice? If you know the type of the collection you are restoring, then you are
usually better off allocating it yourself, then restoring via:
Rwvistream& operator>>(RWvistream&, RWCollectable&);
By using the reference operator, you eliminate the time required for the persistence machinery to
figure out the type of object and have the
RWFactory
allocate one (see
). Furthermore, by allocating the collection yourself, you can tailor the allocation to
suit your needs. For example, you can decide to set an initial capacity for a collection class.