Log in

View Full Version : Creation of buffers with new in constructor or GetFrame method?


vcmohan
2nd November 2006, 05:40
In one of the posts it was pointed out to me that I should not create buffers in the GetFrame method and should create in constructor. My reasoning for that approach is:
I have option to restrict processing for a particular frame range ( without the need to use trim and subsequent joining).
When the call to this function is prior to the range, no buffers are created, and frame is returned immediately. The first time it receives a call GetFrame it creates the buffers. If the frame goes out of range it deletes the buffers. Thereafter it returns frame immediately. Flags for checking buffers are present or not are used. This can be done only in the GetFrame method. This has the advantage that memory not required is released immediately. I think that this method of buffer creation uses least memory in case where large number of trims are used and filtering is done with different parameters. It can also be used in normal way as the default start and end of frame range is 0 to end of clip. But then all buffers will be present throughout.

Will this interfere with set max memory in any way? Can there be crashes due to this. The only overhead I see is a call GetFrame by Avisynth for each frame.

tsp
2nd November 2006, 11:00
I think the SetMemoryMax is only used for avisynth internal cache. I'm not aware of any external plugins that uses it.
As long as you don't assign the buffers to a global/static variable it should be fine.

IanB
3rd November 2006, 03:12
This is effectivly the way the Subtitle filter works. The GDI drawing resources are created when the first frame to be titled is rendered and are release when a frame 10 away from the range is rendered (I recently tweaked the algo in 2.5.7).

Keeping big buffers of state between GetFrame calls is not always effective. Test your filter with Reverse() and Select* in the chain.

Repeated Child->GetFrame calls is not that bad, particularly if SetCacheHints is appropriatly called.

This is C++ not Java so if you new something then you must eventually delete it.