|
Boost Users : |
From: Bo Peng (bpeng_at_[hidden])
Date: 2004-07-18 21:28:47
Dear list,
I have tried many ways but could not figure out how to boost::serialize
the following object:
Basically, to maintain a big chunk of small objects, I use a memory pool
to allocate a big trunk of memory and return the pointers to small
objects.
struct small
{
int size;
int * ptr;
init(int s, int* p){ size = s; ptr = p; }
}
struct All
{
vector<int> data;
vector<small> objs;
All(int num_obj, int size_obj)
{
data.resize( num_obj * size_obj);
for(int i=0; i<num_obj; i++)
objs[i].init( size_obj, &data[i* size_obj]);
}
}
It is easy to serialize All::data but how to deal with small::ptr is
beyond me. I tried the following ways:
1. in small ar & size & ptr. --- template expansion error.
2. in small ar & size & reinterpret_cast<unsigned int>ptr --- core
dump.
What I am trying to do in 2 is that in load(....), I want to
ar & objs; /// get the number of old pointer back.
find the smallest number of objs[i].ptr
relocate objs[i].ptr to &data[0] + objs[i].ptr - smallest point.
However, I can not do this in the load(...) function. The template
expansion does not allow changes to objs (this does not make sense to me
though).
3. ignore ptr --- can compile, core dump.
Can someone give me a bit of insights how I can make things work?
Thanks.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net