std::vector
Copy link to clipboard
Copied
What are folks' opinions on using std::vector for dynamically creating large arrays in AE plugins?
I'm guessing it's as frowned upon as using new and delete, since that's what's probably happening under the hood anyway when you create/resize a vector.
TBH I've tried it in my latest plugin, creating some pretty large vectors, and there's not been any issue, but that's not yet production code.
Copy link to clipboard
Copied
Hi Christian,
I'm using vectors quite often and didn't have any problem.
But the headaches come if you want to share vectors between calls using SequenceData... You'll have to handle flattening unflattening process. Doable, but you loose the simplicity of vectors...
Cheers,
François
Copy link to clipboard
Copied
Hi François,
Good to know, thanks. I had a brief look at allocators afterwards, which might allow us to define a memory allocator using AE's memory suites, which vector can then use (by default a new vector will use std::allocator, which is implicit). I'll post anything that I come up with.
Vectors are rather useful, and nice to use. You're right about having to flatten and unflatten - with this sort of thing it always seems somewhat inefficient, since you need to have a large enough array in your sequence data to take whatever your vector might have stored within.
Cheers, Christian
Copy link to clipboard
Copied
In fact, if you want to flatten / unflatten, you don't need to have an array in your sequence data.
You should have a look at this thread:
Using std::vector in sequence_data
Toby litterally saved my life on this one!
Cheers,
François
Copy link to clipboard
Copied
Thankfully I'm using no sequence data in my current plugin but thanks for the link.
I was wondering how much of a potential performance hit flattening and unflattening sequence data on a frame-by-frame basis might introduce with the latest AE versions. With large arrays in vectors this must introduce some kind of slowdown, right?
Cheers, C
Copy link to clipboard
Copied
Well, if you're calling your data from the same call each time (render), I don't see any need for flattening unflattening.
Troubles come when you use the same data in different calls. You can have a look at this one:
Sequence_data different in PF_Cmd_RENDER and PF_Cmd_USER_CHANGED_PARAM
See? I've been bothering everyone with my vectors 😉
Cheers,
François
Copy link to clipboard
Copied
Hi Christian, I wonder if you managed to create std::vector by using AE's memory functions ?
Thanks !
Gab

