Pump Versus Callback: A Gentleman's Dilemma
^_^
Admit it! The title totally had you curious.
In any event, I'm looking for opinions on something for my library code. Again.
This time it is the iterative processing approach versus a callback based approach.
As usual, I could do either; this is simply about harvesting opinions so that the default approach feels comfortable to the widest audience.
I'll show the iterative processing approach first.
Code:
// ...
struct SomeData;
// ...
// ...
SomeData lSomeData;
// ...
// ...
while(lResult = DoSomething(lSomeData))
{
if(lResult == MOREMEMORY)
{
// ...
// Expand memory allocation associated with `lSomeData'
// for use by `DoSomething'.
// ...
}
}
// ...
Now I'll show a callback based approach.
Code:
// ...
struct SomeData;
// ...
// ...
bool MyProcessSomeData
(
SomeData & fSomeData
, NIdentifier fReason
)
{
if(fReason == MOREMEMORY)
{
// ...
// Expand memory allocation associated with `fSomeData'
// for use by `DoSomething'.
// ...
}
}
// ...
// ...
SomeData lSomeData;
// ...
// ...
DoSomething(lSomeData, MyProcessSomeData);
// ...
Soma