Question
Wrapping memory allocation for after effects
Hello,
In AE memory allocation parts, it s stated:
If you’re wrapping existing C++ classes, create a base class that implements new and delete for that class and derive from it. To overload the STL, we don’t recommend you overload global new and delete. Instead provide an allocator as part of the template definition.
I think it would be good to have some examples of how we are supposed to do it. allocator being very complicated, and i m not sure how we are suppose to use the handle suite to do that.
Just to explain my point, the new and delete operator overload would look somehow like that:
PF_Handle pdata;
void *MyClass::operator new(size_t size)
{
void *p;
AEFX_SuiteScoper< PF_HandleSuite1> handle_suite(in_data, kPFHandleSuite, kPFHandleSuiteVersion1);
pdata= handle_suite->host_new_handle(sizeof( MyClass ));
{
void *p;
AEFX_SuiteScoper< PF_HandleSuite1> handle_suite(in_data, kPFHandleSuite, kPFHandleSuiteVersion1);
pdata= handle_suite->host_new_handle(sizeof( MyClass ));
p=handle_suite->host_lock_handle( pdata ));
???handle_suite->host_unlock_handle( pdata )); ???
return p;
}
void MyClass ::operator delete(void *p)
{
return p;
}
void MyClass ::operator delete(void *p)
{
AEFX_SuiteScoper< PF_HandleSuite1> handle_suite(in_data, kPFHandleSuite, kPFHandleSuiteVersion1);
???handle_suite->host_unlock_handle( pdata )); ???
handle_suite->host_dispose_handle( pdata );
}
handle_suite->host_dispose_handle( pdata );
}
My questions is about the two lines:
p=handle_suite->host_lock_handle( pdata ));
handle_suite->host_unlock_handle( pdata ));
if i unlock the PF_handle just after the lock, it means, i think, that the memory could be move and the pointer i just return could become invalid any time soon...
so should i keep it lock and unlock in the destructor? meaning i ll have some small chunk of memory in AE memory pool that will be locked for as long as my object lives...
it s a c++ question, but it s related on how AE works internally, so i d be happy to get more details about that.
thanks in advance.
