VirtualDub过滤器帧缓冲区-释放内存 [英] VirtualDub filter framebuffer - freeing memory
问题描述
我正在编写一个VirtualDub过滤器,它需要一个单独的帧缓冲区来在fa-> src.data和fa-> dst.data(.data本质上是指向Pixel数据的指针)之间进行中间图像处理.
I am writing a VirtualDub filter, which requires a separate frame buffer for intermediate image processing between fa->src.data and fa->dst.data (.data is essentially a pointer to Pixel data).
我使用以下代码创建指向上述字符的char指针:
I create a char pointer to the above using this:
/* Pointers to source and destination frame stores */
char *src = (char *)fa->src.data;
char *dst = (char *)fa->dst.data;
/* Image width and height */
int w = fa->src.w*sizeof(Pixel32);
int h = fa->src.h*sizeof(Pixel32);
然后,这允许我逐行将数据从源帧复制到目标帧:
This then allows me to copy data from source frame to destination frame, line by line:
memcpy(dst,src,w);
现在,我希望有一个中间缓冲区,我可以将其从* dst复制到缓冲区,然后从缓冲区复制到* src.我该怎么办?
Now I would like to have an intermediate buffer that I can copy from *dst to buffer, then from buffer to *src. How can I do that?
我尝试了几项不同程度的成功.
I tried several things with varying degrees of success.
/* Define and initialise char array with malloc */
char *buf = (char*)malloc(w*h);
然后:
memcpy(buf,src,w); /* copy to buffer */
memcpy(dst,buf,w); /* copy from buffer to dst */
在大多数情况下,这似乎可行.但是,过了一会儿,我收到模块中发生越界内存访问(访问冲突)".问题是我似乎用完了系统内存(VirtualDub会在一段时间后占用所有可用内存).
Most of the time, this seems to work. However, after a short while I get "An out-of-bounds memory access (access violation) occurred in module ". The issue is that I seem to run out of system memory (VirtualDub takes ALL the available memory after a while).
我需要释放缓冲区吗?似乎很奇怪,因为它是每帧初始化的.我该如何释放它?
Do I need to free the buffer? Seems odd, since it is initialised every frame. How can I free it?
我尝试了free(dstbuf)和free(& dstbuf),但是在运行时出现调试断言失败"错误,表达式:_CrtIsValidHeapPointer(pUserData)...其他不多了.
I tried free(dstbuf) and free(&dstbuf) but I am getting "Debug Assertion Failed" error at runtime, expression: _CrtIsValidHeapPointer(pUserData)... with not much else.
有什么想法吗?
推荐答案
通过每次运行仅分配一次内存来解决.没有理由为每一帧分配内存,因为我一次只需要保留一帧.
Resolved by allocating memory only once per run. There's no reason to allocate memory for each frame, since I only need to hold one frame at a time.
这篇关于VirtualDub过滤器帧缓冲区-释放内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!