Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ Memory leak while trying to delete first element of linkedlist of pointers
    primarykey
    data
    text
    <p>I'm quite new to C++ and I'm having a big problem for two days now. I'm trying to do multithreaded rendering (raycasting, multisampling, ambientocclusion) with posix threads and everytime I run the program, it consumes about 5GB of RAM (after start of threads) until termination. So obviously I have a memory Leak. My working threads work like this:</p> <pre><code>struct Job { AOSampler sampler; Ray ray; bool abool; int someint; . . //no pointers here }; //global //use of C++ STL list list&lt;Job*&gt; * jobs; //Part of thread posix function starts here list&lt;Job*&gt; tjobs; // Mark 1 //Pushing and popping between "tjobs" the threadjobs just for this thread and the global jobpool "jobs". Of course threadsafe with mutex locking. //The thread pops jobs from "jobs" and puts em into "tjobs" while(!tjobs.empty()) { //many calculations but all vars are on stack, besides creating new jobs an pushing them to some other queue, which will be pushed into "jobs" later // !!!THE PROBLEM!!! delete (tjobs.front()); tjobs.pop_front(); // The memory in htop always rises but never decreases! } // jumps to Mark 1 // end of multithread while </code></pre> <p>The code is compiling and running and terminating on many cores but performance is bad(4 ok, 24 bad, its a 24 core machine). I think it might be because of the 5GB memory usage (quarter of all phys. ram), but well OS and cache might not be able to handle this well.</p> <p>I'm desperate about finding a solution to my problem. My googling didn't help me at all. I hop you can do. any help is highly appreciated.</p> <p>Thank you</p> <p>(sorry for my english)</p> <p>Edit1: forgot to mention, that it has no output yet -> I can't verify if it is valid</p> <p>Edit2: Some headers:</p> <pre><code>class AOSampler { public: AOSampler(); /// constructor that initializes the sampler, just calls init AOSampler(vec3 const &amp; normal, vec3 const &amp; color); /// initializes the sampler void init(vec3 const &amp; normal, vec3 const &amp; color); /// returns an importance sampled random direction and the associated weight void sample(vec3 &amp; sampledDirection, vec3 &amp; sampleWeight) const; private: /// orthonormal basis vec3 m_normal; vec3 m_tangent; vec3 m_bitangent; /// diffuse color vec3 m_color; }; class Ray { public: Ray() : tMin(0.001f), tMax(FLT_MAX){} vec3 origin; vec3 direction; float tMin, tMax; }; class vec3 { public: float x,y,z; vec3(); vec3(float a, float b, float c); /// assignment operator that assigns a single scalar value to all components void operator=(float v); /// unsafe element access float operator[](unsigned int i) const { return (&amp;x)[i]; } /// length of the vector float length() const; ///Returns a normalized version of the vector vec3 normalize() const; /// componentwise summation vec3 add(const vec3&amp; a) const; /// componentwise subtraction vec3 subtract(const vec3&amp; a) const; ///compute the dot product which is cos(alpha) * this.Length * a.Length ///where alpha is the (smaller) angle between the vectors float dot(const vec3&amp; a) const; float minComponent() const; float maxComponent() const; ///computes a vector which is orthogonal to both of the input vectors static vec3 cross(const vec3&amp; a, const vec3&amp; b); static vec3 min(const vec3&amp; a, const vec3&amp; b); static vec3 max(const vec3&amp; a, const vec3&amp; b); /// add a vector to this vector void operator+=( vec3 const &amp; v ); /// subtract a vector from this vector void operator-=( vec3 const &amp; v ); }; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload