unidan 評論 5 年之前'
```
class DecoderOwnerBase
{
virtual void* new_picture = 0;
};
class DecoderOwnerDynamic : DecoderOwnerBase
{
public:
void* new_picture(void*) override;
private:
void *sys;
};
class DecoderOwnerStatic : DecoderOwnerBase
{
public:
void* new_picture(void*) override;
private:
Priv bar;
};
template<DecoderOwner>
class DecoderModuleStatic : DecoderOwner
{
void decode() {
void * pic = new_picture();
}
};
class DecoderModuleDynamic
{
DecoderModuleDynamic(DecoderOwnerBase *owner);
};
/* Full static:
* + allocation must be made together
* + size must be known */
DecoderModuleStatic<DecoderOwnerStatic>;
/* Owner data dynamic + Owner static
* + the owner object visible to the module is always the same
* + no need to know the real owner size
* + one owner object allocated per module */
DecoderModuleStatic<DecoderOwnerDynamic>;
/* Owner data static + Owner dynamic */
DecoderModuleDynamic(new DecoderOwnerStatic);
/* Full dynamic */
DecoderModuleDynamic(new DecoderOwnerDynamic(priv));
```