我没有泄漏,我实际上有一个排水管因此很容易找到,但我似乎无法做到。
我运行了一个openGL程序并对glReadPixels
执行boost::interprocess::shared_memory_object
,运行正常。我的问题在于读取共享内存的程序(实际上是另一个openGL程序的openGL纹理),这会直接增加内存使用量......
我试图解决这个问题,但不太了解问题所在。
Valgrind报告没有泄漏:
==6697== HEAP SUMMARY:
==6697== in use at exit: 116 bytes in 3 blocks
==6697== total heap usage: 35,975 allocs, 35,972 frees, 2,784,987,994 bytes allocated
==6697==
==6697== LEAK SUMMARY:
==6697== definitely lost: 0 bytes in 0 blocks
==6697== indirectly lost: 0 bytes in 0 blocks
==6697== possibly lost: 0 bytes in 0 blocks
==6697== still reachable: 116 bytes in 3 blocks
==6697== suppressed: 0 bytes in 0 blocks
但令我困惑的是堆usag,我使用共享内存的方式是在函数显示中:
using namespace boost::interprocess;
void display(void)
{
/* setup texture*/
GLuint textureID;
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);
shared_memory_object shm (open_only,"shared",read_only);
mapped_region region(shm, read_only);
char *mem = static_cast<char*>(region.get_address());
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA, 720, 576, 0, GL_BGRA,GL_UNSIGNED_BYTE,(GLvoid*)mem);
分配的共享内存只有1658880字节,为什么它会继续增长?
有人能帮助我走上正轨吗?有什么方法可以释放变量吗?我尝试过的所有内容都以段落错误结束。
编辑: 我的测试的完整代码是:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <GL/glew.h>
#include <GL/freeglut.h>
#include <GL/gl.h>
#include <boost/interprocess/mapped_region.hpp>
#include <boost/interprocess/shared_memory_object.hpp>
#include <thread>
#include <chrono>
using namespace std;
using namespace boost::interprocess;
void display(void)
{
/* setup texture*/
GLuint textureID;
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);
/*grab data from shared memory*/
shared_memory_object shm (open_only,"partilha",read_only);
mapped_region region(shm, read_only);
char *mem = static_cast<char*>(region.get_address());
/*----------------------------------*/
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA, 720, 576, 0, GL_BGRA,GL_UNSIGNED_BYTE,(GLvoid*)mem);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);
glBegin(GL_POLYGON);
glTexCoord2f (0.0, 0.0);
glVertex3f (0.0, 0.0, 0.0);
glTexCoord2f (1.0, 0.0);
glVertex3f (1.0, 0.0, 0.0);
glTexCoord2f (1.0, 1.0);
glVertex3f (1.0, 1.0, 0.0);
glTexCoord2f (0.0, 1.0);
glVertex3f (0.0, 1.0, 0.0);
glEnd();
glFlush ();
glutPostRedisplay();
}
void init (void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glEnable(GL_TEXTURE_2D);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (720, 576);
glutInitWindowPosition (100, 100);
glutCreateWindow ("output");
init ();
while (true)
{
glutDisplayFunc(display);
glutMainLoopEvent();
this_thread::sleep_for (std::chrono::milliseconds(20));
}
return 0;
}
所以,实际上我每秒使用60次显示功能......这就是总结记忆的东西,但是在功能结束时它会被破坏吗?我怎么能毁掉它?感谢