Closed AnnulusGames closed 8 months ago
It would be better to return NativeAnimationCurve to application shared pool as much as possible. And returning to pool on MotionStorage.Reset is also needed. (I think you already know this.)
Yes, it's definitely better from a memory consumption perspective. However, returns to the pool are somewhat complex to incorporate into current implementations, and there is a risk of double returns. (This can be avoided by adding some checks, but it will reduce performance during creation.) In the current implementation, in the worst case, as many NativeAnimationCurves as there are elements in the MotionData array are created. However, this is rarely a problem in practice.
NativeAnimationCurve should be named UnsafeAnimationCurve, and NativeAnimationCurve should be a pointer wrapper. (This allows to share memory with planned functionPointer.)
I think FunctionPointer and NativeAnimationCurve should be kept in separate fields. In particular, the delegates generated by FuncitonPointer need to be cached if Burst is not used, and handling them with a single pointer complicates this process. The concern is that the structure size will increase, but this shouldn't be a problem since MotionData is originally a huge struct and was designed to avoid copying. (Also, from a safety perspective, I would like to avoid implementations that do not use AtomicSafetyHandle.)
My main concern with this implementation is the risk of memory leaks and double freeing. They have passed minimal testing and should not be a problem, but I am not too sure... (especially the crash caused by double deallocation, which must be avoided at all costs...)
OK, but considering EnterPlayModeSettings, it is mandatory to dispose or pool with MotionStorage.Reset.
Yes, I think so. In that case, would it be better to have the Allocator on the MotionStorage side?
As for naming, I think it is inevitable that NativeAnimationCurve will be UnsafeAnimationCurve if we follow Unity's naming rules. (like UnsafeList and NativeList)
I consider containers whose safety is checked by AtomicSafetyHandle to be Native-, and containers that are not checked to be Unsafe-. Considering this, wouldn't Native- be more appropriate in this case?
Sorry, you seem to be right. I was mistaken, as the behavior of the field being overwritten by CopyFrom is not seen in Native-.
Isn't it safe to release animationcurve in MotionStorage.RemoveAll? If this causes some issue, it means the current implementation of MotionStorage is incorrect.
I considered several implementations and made changes to the implementation.