Correct Memory Allocation ae sdk

New Here ,
Nov 16, 2020

Copy link to clipboard

Copied

Hello,

i am asking my self what is the correct way to setup my global and sequence data with my custom class.
As mentioned in the docs i need to create a base class with overriden new and delete operators (https://ae-plugin-sdk-guide.readthedocs.io/effect-details/memory-allocation.html).

But when i create a new handle with PF_NEW_HANDLE and locking it afterwards the "new" function will not be called. What is the correct way to do it?

example code:

class BaseClass
{
public:
	virtual ~BaseClass()
	{
	}

	BaseClass() = default;
	BaseClass(const BaseClass&) = default;
	BaseClass& operator=(const BaseClass&) = default;

	void* operator new(std::size_t size)
	{
		return ::operator new(size);
	}

	void operator delete(void* ptr)
	{
		::operator delete(ptr);
	}
};


class Global : public BaseClass
{
	CustomClass1* member1_m;
	CustomClass2 member2_m;
	

public:


	Global()
	{
		
	}
	Global(const Global&) = default;
	Global& operator=(const Global&) = default;
}



	

 

and i am creating the handle ins GlobalSetup

static PF_Err
GlobalSetup(
	PF_InData* in_data,
	PF_OutData* out_data,
	PF_ParamDef* params[],
	PF_LayerDef* output)
{
	PF_Err err = PF_Err_NONE;

	PF_Handle globH = NULL;
	
	globH = PF_NEW_HANDLE(sizeof(Global));


	if (globH)
	{
		Global* global  = static_cast<Global*>(PF_LOCK_HANDLE(globH));
		
		PF_UNLOCK_HANDLE(globH);
		out_data->global_data = globH;
		
	}
	else
	{
		err = PF_Err_INTERNAL_STRUCT_DAMAGED;
	}

	return err;
}

 

TOPICS
Effects and Titles, Error or problem, SDK

Views

36

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Have something to add?

Join the conversation