Tymek
Tymek

Reputation: 684

How do I serialize a Boost scoped_array using Boost serialization?

I am trying to serialize a Boost scoped_array using Boost serialization but the compiler (VS2008) is giving me the following error message:

error C2039: 'serialize' : is not a member of 'boost::scoped_array<T>'

How do I serialize a scoped_array? Is there a Boost library that I should be including for this?

Upvotes: 2

Views: 660

Answers (3)

Tymek
Tymek

Reputation: 684

Here is a solution that I ended up using (symmetric -- works for saving and loading):

void myClass::serialize(Archive & ar, const unsigned int file_version)
{
    ar & myScopedArraySIZE;

    // Only gets called during loading
    if (Archive::is_loading::value)
    {
        myScopedArray.reset(new ColourPtr[myScopedArraySIZE]);
    }

    for (uint i = 0; i < myScopedArraySize; i++)
    {
        ar & myScopedArray[i];
    }
}

Upvotes: 0

Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385254

Serialise the array itself, not a memory-managing wrapper around it.

Upvotes: 0

Bo Persson
Bo Persson

Reputation: 92301

Guess not. The scoped_ptr and scoped_array are designed for keeping track of pointers in a local scope.

The scoped_ptr template is a simple solution for simple needs. It supplies a basic "resource acquisition is initialization" facility, without shared-ownership or transfer-of-ownership semantics. Both its name and enforcement of semantics (by being noncopyable) signal its intent to retain ownership solely within the current scope.

Having the content serialized and read back later seems to be against the intent of the class.

Upvotes: 1

Related Questions