<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Kann memory leak in Ladefunktion nicht finden :(]]></title><description><![CDATA[<p>Guten Tag.</p>
<p>Ich habe eine Funktion zum laden von Texturen, welche mit VS und Windows problemlos funktioniert leicht abgeändert, damit sie unter Linux mit g++ compiled - z.B. Byte definiert.</p>
<p>Das funktionierte soweit auch (Textur wird korrekt geladen und angezeigt). Allerdings werden die 8GB Ram recht schnell voll und dann gehts abwärts...</p>
<p>Hier die Funktion:</p>
<pre><code class="language-cpp">#include &quot;GL/gl.h&quot;
#include &quot;GL/glu.h&quot;
#include &quot;stdio.h&quot;
#include &quot;stdlib.h&quot;

namespace KGLL {

  typedef unsigned char BYTE;   // 8-bit unsigned entity.

GLuint LoadTextureRAW( const char * filename, int wrap )
{
  GLuint texture;
  int width, height;
  BYTE * data;
  FILE *file;

  // open texture data
  file = fopen( filename, &quot;rb&quot; );
  if ( file == NULL ) return 0;
  // allocate buffer
  width = 1024;
  height = 1024;

  data = (BYTE *) malloc( width * height * 3 );
  // read texture data
  fread( data, width * height * 3, 1, file );
  fclose( file );
  // allocate a texture name
  glGenTextures( 1, &amp;texture );
  // select our current texture
  glBindTexture( GL_TEXTURE_2D, texture );
  // select modulate to mix texture with color for shading
  glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
  // when texture area is small, bilinear filter the closest MIP map
  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
  // when texture area is large, bilinear filter the first MIP map
  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
  // if wrap is true, the texture wraps over at the edges (repeat)
  //       ... false, the texture ends at the edges (clamp)
  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap ? GL_REPEAT : GL_CLAMP );
  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap ? GL_REPEAT : GL_CLAMP );
  // build our texture MIP maps
   gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_UNSIGNED_BYTE, data );
  // free buffer
  free( data );
  return texture;
}
</code></pre>
<p>Jemand eine Idee?</p>
<p>Unter Windows war noch anders:</p>
<pre><code class="language-cpp">data = malloc( width * height * 3 );
</code></pre>
<p>Ich programmiere normalerweise mit Delphi und habe daher nur begrenztes C++ Wissen.</p>
<p>Vielen Dank.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/283919/kann-memory-leak-in-ladefunktion-nicht-finden</link><generator>RSS for Node</generator><lastBuildDate>Sat, 22 Aug 2026 10:18:23 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/283919.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 22 Mar 2011 09:53:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Kann memory leak in Ladefunktion nicht finden :( on Tue, 22 Mar 2011 09:53:26 GMT]]></title><description><![CDATA[<p>Guten Tag.</p>
<p>Ich habe eine Funktion zum laden von Texturen, welche mit VS und Windows problemlos funktioniert leicht abgeändert, damit sie unter Linux mit g++ compiled - z.B. Byte definiert.</p>
<p>Das funktionierte soweit auch (Textur wird korrekt geladen und angezeigt). Allerdings werden die 8GB Ram recht schnell voll und dann gehts abwärts...</p>
<p>Hier die Funktion:</p>
<pre><code class="language-cpp">#include &quot;GL/gl.h&quot;
#include &quot;GL/glu.h&quot;
#include &quot;stdio.h&quot;
#include &quot;stdlib.h&quot;

namespace KGLL {

  typedef unsigned char BYTE;   // 8-bit unsigned entity.

GLuint LoadTextureRAW( const char * filename, int wrap )
{
  GLuint texture;
  int width, height;
  BYTE * data;
  FILE *file;

  // open texture data
  file = fopen( filename, &quot;rb&quot; );
  if ( file == NULL ) return 0;
  // allocate buffer
  width = 1024;
  height = 1024;

  data = (BYTE *) malloc( width * height * 3 );
  // read texture data
  fread( data, width * height * 3, 1, file );
  fclose( file );
  // allocate a texture name
  glGenTextures( 1, &amp;texture );
  // select our current texture
  glBindTexture( GL_TEXTURE_2D, texture );
  // select modulate to mix texture with color for shading
  glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
  // when texture area is small, bilinear filter the closest MIP map
  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
  // when texture area is large, bilinear filter the first MIP map
  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
  // if wrap is true, the texture wraps over at the edges (repeat)
  //       ... false, the texture ends at the edges (clamp)
  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap ? GL_REPEAT : GL_CLAMP );
  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap ? GL_REPEAT : GL_CLAMP );
  // build our texture MIP maps
   gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_UNSIGNED_BYTE, data );
  // free buffer
  free( data );
  return texture;
}
</code></pre>
<p>Jemand eine Idee?</p>
<p>Unter Windows war noch anders:</p>
<pre><code class="language-cpp">data = malloc( width * height * 3 );
</code></pre>
<p>Ich programmiere normalerweise mit Delphi und habe daher nur begrenztes C++ Wissen.</p>
<p>Vielen Dank.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2038063</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2038063</guid><dc:creator><![CDATA[kgh]]></dc:creator><pubDate>Tue, 22 Mar 2011 09:53:26 GMT</pubDate></item><item><title><![CDATA[Reply to Kann memory leak in Ladefunktion nicht finden :( on Tue, 22 Mar 2011 11:48:33 GMT]]></title><description><![CDATA[<p>Hallo kgh,</p>
<p>vermutlich gibst du deine Texturen nicht wieder frei, nachdem sie nicht mehr benutzt werden.</p>
<pre><code class="language-cpp">void glDeleteTextures(GLsizei n, const GLuint *textures);
</code></pre>
<p>Viele Grüße,<br />
MaBa</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2038133</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2038133</guid><dc:creator><![CDATA[MaBa]]></dc:creator><pubDate>Tue, 22 Mar 2011 11:48:33 GMT</pubDate></item><item><title><![CDATA[Reply to Kann memory leak in Ladefunktion nicht finden :( on Tue, 22 Mar 2011 12:21:32 GMT]]></title><description><![CDATA[<p>Hey super! Genau daran lag es!</p>
<p>Vielen Dank!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2038168</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2038168</guid><dc:creator><![CDATA[kgh]]></dc:creator><pubDate>Tue, 22 Mar 2011 12:21:32 GMT</pubDate></item><item><title><![CDATA[Reply to Kann memory leak in Ladefunktion nicht finden :( on Tue, 22 Mar 2011 15:08:56 GMT]]></title><description><![CDATA[<p>Kleiner Tip: schau dir mal C++ an. Außer dem Namespace war das alles C:</p>
<p>- &quot;stdio.h&quot; und &quot;stdlib.h&quot; heißen in C++ &lt;cstdio&gt; und &lt;cstdlib&gt;<br />
- Für Dateioperationen gibts fstreams, die schließen sich beispielsweise von selber (Stichwort RAII)<br />
- statt malloc benuttz man in C++ meist new - und statt new für einfache byte-Arrays kann man auch vector benutzen, der den Speicher automatisch wieder freigibt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2038322</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2038322</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Tue, 22 Mar 2011 15:08:56 GMT</pubDate></item></channel></rss>