wonkey_monkey
31st May 2021, 13:47
I'm writing a plugin where all instances need to access one instance of a variable (a vector). I can declare it as static and this works fine.
But the problem arises that the variable is shared even across different IScriptEnvironments, so that if my process tries to create a new IScriptEnvironment (which it does when reloading an .avs file, to check that it's valid before deleting the old environment), any instances of the plugin in the new script environment can still see the data in the vector from the old instance.
One thought that occurs to me is to add a new function to the plugin which serves only to store, and return a pointer to, the vector. This would (if I understand correctly) have to be disguised as an AVSValue, and for x64 it would to be a 64-bit value. I think that means it would have to be cast to either a PClip - which could causes problems as it wouldn't be a real smart pointer to a clip? - or I see there's also a .AsDblDef member of AVSValue. But I thought I'd heard pinterf say recently that there weren't any 64-bit AVSValues...
EDIT: Scrap that. The new function would have to have the vector as a static variable just the same as before, and would therefore run into the same problem.
Is there any way of doing this? Can I tack my variable's pointer onto the environment somewhere?
Edit: I could keep track of the env pointer, and separate the entries in the vector that way, but that sounds dodgy. Not that I expect the vector to get very big, but it would be a leak because I don't think I'd have any way of knowing that a particular environment had been destroyed. Plus the other instances wouldn't be able to update their indices if the entries in the vector were deleted.
But the problem arises that the variable is shared even across different IScriptEnvironments, so that if my process tries to create a new IScriptEnvironment (which it does when reloading an .avs file, to check that it's valid before deleting the old environment), any instances of the plugin in the new script environment can still see the data in the vector from the old instance.
One thought that occurs to me is to add a new function to the plugin which serves only to store, and return a pointer to, the vector. This would (if I understand correctly) have to be disguised as an AVSValue, and for x64 it would to be a 64-bit value. I think that means it would have to be cast to either a PClip - which could causes problems as it wouldn't be a real smart pointer to a clip? - or I see there's also a .AsDblDef member of AVSValue. But I thought I'd heard pinterf say recently that there weren't any 64-bit AVSValues...
EDIT: Scrap that. The new function would have to have the vector as a static variable just the same as before, and would therefore run into the same problem.
Is there any way of doing this? Can I tack my variable's pointer onto the environment somewhere?
Edit: I could keep track of the env pointer, and separate the entries in the vector that way, but that sounds dodgy. Not that I expect the vector to get very big, but it would be a leak because I don't think I'd have any way of knowing that a particular environment had been destroyed. Plus the other instances wouldn't be able to update their indices if the entries in the vector were deleted.