Skip to main content
Known Participant
March 8, 2022
Question

Wrapping memory allocation for after effects

  • March 8, 2022
  • 1 reply
  • 627 views

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 ));
    p=handle_suite->host_lock_handle( pdata  ));    
    ???handle_suite->host_unlock_handle( pdata  ));    ???
    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  );
}
 
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.
This topic has been closed for replies.

1 reply

Community Manager
March 8, 2022

Hi marc tokyo,

 

Good question. The handle lock and unlock calls no longer do anything in After Effects so you can leave those out.

 

Cheers,

Jason

Known Participant
March 8, 2022

wow, that a very big news.

Nothing is written in the documentation about that, so i wonder from which After effects version this is true, since we are supporting multiple versions.

also instead of using the lock function, shall we just do a cast of PF_Handle?

Community Manager
March 8, 2022

It looks like this goes back roughly 10 years, likely first shipping in CS 6.