On 7/9/2014 7:56 AM, fl wrote:
[..] I have read
a book about handle, but I still cannot know how to use it
in my problem. My problem can be simplified as a large data
input block. Each processing stage does some operation on it.
The output has less data than input. For example, a 400 data
input block is at the input of the first stage. Its output
has 100 data. The second processing stage has these 400 data
as input and its output has 25 data. The third processing
has these 25 data as input, and its output will be 5 data.
I want the 100 data and 25 data are not copied between
processing stages. Could you explain about how to use
a handle for these processing?
8-O What book are you reading that doesn't explain that???
Suppose I have two classes, A and B that "play ping-pong" with some data
and the data are an array of integer values.
class DataOwner {};
struct RawData {
DataOwner *m_boss;
int m_data[5000000];
// this is not necessary in this example
void belong2(DataOwner* iamthebossnow) { m_boss = iamthebossnow; }
};
typedef RawData *DataHandle;
const DataHandle noData = nullptr;
class A : public DataOwner
{
DataHandle m_dataHandle;
public:
DataHandle ping(DataHandle h)
{
h->belong2(this);
// process h->m_data, for instance
// assign h to m_dataHandle, call other members
// and so on. Watch out for m_dataHandle's
// becoming stale -- that's the source of all
// kinds of errors
return h;
}
};
class B : public DataOwner
{
DataHandle m_dataHandle;
public:
DataHandle pong(DataHandle h)
{
h->belong2(this);
// process h->m_data ...
return h;
}
};
int main()
{
DataHandle data = new RawData();
A a;
B b;
a.ping(data);
b.pong(data);
a.ping(b.pong(a.ping(data)));
delete data;
}
Better, of course, to use 'std::shared_ptr' for the handle...
Thank you, Victor. Your post is really helpful for me. I also want to use t=
he ping-pong structure. In my project, module A works as input while module=
B works as the second stage. That is, B accepts A's output as input. I gue=
ss that your code also applies to this cascaded stage structure.
wner {}; . Of course, A and B use the the same memory. They have the same m=
emory structure. Could you tell me a little example content of the base cla=