[OpenWalnut-Dev] mystisches Speicherproblem

Christian Heine cheine at inf.ethz.ch
Fri Jun 22 16:35:11 CEST 2012


Hi,

sorry to disagree. vector<Foo>().swap(my_foo_vec) is the only pragmatic 
way to reduce the capacity of vector my_foo_vec. (See e.g. Scott 
Meyers). The capacity reduction, however, is not guaranteed for any 
operation in the C++ standard. Capacity can only be increased explicitly.

@Patrick: do not clear() and resize() the vector before swapping. After 
swap add an assert(m_matrix.capacity() == 0). But I suspect the culprit 
to be someone else.

In a world without Qt4 and OSG, valgrind is your friend.

Best Regards,
Christian

On 22.06.2012 16:18, math at informatik.uni-leipzig.de wrote:
> Hi Patrick, I just read your mail and one thing came to my mind. Swap,
> clear,resize may not reduce the capacity which is what std::vector
> allocates. Please try setting capacity explicitly and dont use swap
> unless you can give a substantial reason and report back. I couldnt test
> myself.
>
> Sent from my android device.
>
>
>
> -----Original Message-----
> From: Patrick Oesterling <oesterling at informatik.uni-leipzig.de>
> To: openwalnut-dev at lists.informatik.uni-leipzig.de
> Sent: Fri, 22 Jun 2012 16:03
> Subject: [OpenWalnut-Dev] mystisches Speicherproblem
>
> Hallo OW-Developer,
>
> da es meine erste Nachricht ist, zunächst ein großes Lob an alle
> Verantwortlichen, die OW in seinen heutigen Zustand gebracht haben. Es
> macht mir gewissermaßen "Spaß", meine bisherige Arbeit damit zu
> implementieren.
>
> Ich bin leider auf ein ziemlich merkwürdiges Speicherproblem im OW
> gestoßen, welches dazu führt, dass der RAM überläuft (auf allen Rechnern
> die ich getestet habe). Da ich mit Sebastian bereits vergeblich eine
> ganze Menge Zeit investiert habe, hoffe ich nun, dass evtl von euch
> jemand eine Ahnung/Idee hat, was genau hier (theoretisch) "schief" läuft.
>
>
> Auf folgende Weise kann das Szenario schnell und einfach reproduziert
> werden:
>
>
> [ 1) OW auschecken ]
>
> 2) als private member im Template-Modul in der WMTemplate.h folgendes
> deklarieren
>
> std::vector< std::vector< double > > m_matrix;
>
> 3) in der moduleMain() in der WMTemplate.cpp beim m_aTrigger event (ca.
> line: 629) folgendes einfügen
>
> int size = 0;
> std::cin >> size;
>
> // free old matrix ( just to be sure )
> m_matrix.clear();
> m_matrix.resize( 0 );
> std::vector< std::vector< double > >().swap( m_matrix );
> m_matrix = std::vector< std::vector< double > >();
>
> // allocate new (triangle) matrix
> for( int i = 0; i < size; ++i )
>       m_matrix.push_back( std::vector< double >( i + 1, 0.0 ) );
>
> 4) OW starten - trigger auslösen - 30000 <tel:30000> eingeben
>
> 5) mit "top" (linux command) oder "gnome-system-monitor" beobachten, wie
> der RAM um ca. 4 GB steigt
>
> jetzt zum Problem:
>
> 6) trigger erneut auslösen - 30 (oder irgendwas << 30000 <tel:30000>)
> eingeben und
> beobachten, wie der Speicher der member variablen -NICHT- komplett
> wieder freigegeben wird.
>
> Scheinbar willkürlich wird von den 4GB mal mehr oder weniger (laut
> "top") wieder freigegeben, oder leider auch mal gar nichts. Richtig
> unangenehm wird die Geschichte, weil nach mehrmaligen Auslösen des
> Triggers sogar ein Vielfaches des Speichers belegt wird (bis der RAM
> halt voll ist) ( -> einfach zweimal mit halber RAM-Größe auslösen, um es
> zu beschleunigen).
>
> Dass "top" etwas falsches anzeigt, scheidet meiner Meinung nach aus,
> weil a.) letztendlich tatsächlich geswapt wird (obwohl es nur eine
> Instanz geben sollte) und weil b.) folgender "helloWorld" Ansatz
> einwandfrei funktioniert (laut "top"):
>
> ---------------------------
>
> #include <iostream>
> #include <vector>
>
> int main()
> {
>     std::vector< std::vector< double > > matrix;
>
>     int size = 0;
>     while( true)
>     {
>       std::cin >> size;
>
>       if( size == 0)
>           break;
>
>       // free matrix
>       std::vector< std::vector < double > >().swap( matrix );
>
>       // allocate matrix
>       for( int i = 0; i < size; ++i )
>           matrix.push_back( std::vector< double >( i+1, 0.0 ) );
>     }
> }
>
> ---------------------------
>
> Falls einer von euch eine Ahnung hat, was im OW (threading, libraries,
> etc) dafür verantwortlich sein könnte, oder ob hier prinzipielle Dinge
> verantwortlich sind, wäre ich sehr dankbar. Angeblich existiert auch nur
> immer eine Instanz eines Moduls (hier: des Template Moduls).
>
>
> Folgendes habe ich außerdem probiert:
>
> 1.) alle Einzelfälle bei "free memory" (siehe oben)
> 2.) boost::shared_ptr< std::vector< std::vector< double > > > m_matrix
> 3.) helloWorld Ansatz mit Klassen-member und boost::threads ( "top"
> zeigt weiterhin korrekt an)
> 4.) helloWorld Ansatz mit Klassen-member und Funktionalität in extra
> library ( "top" zeigt weiterhin korrekt an)
>
>
> Vielen Dank schonmal.
> Patrick
> _______________________________________________
> OpenWalnut-Dev mailing list
> OpenWalnut-Dev at lists.informatik.uni-leipzig.de
> <mailto:OpenWalnut-Dev at lists.informatik.uni-leipzig.de>
> http://lists.informatik.uni-leipzig.de/mailman/listinfo/openwalnut-dev
>
> Archive: http://lists.informatik.uni-leipzig.de/pipermail/openwalnut-dev/
>
>
>
> _______________________________________________
> OpenWalnut-Dev mailing list
> OpenWalnut-Dev at lists.informatik.uni-leipzig.de
> http://lists.informatik.uni-leipzig.de/mailman/listinfo/openwalnut-dev
>
> Archive: http://lists.informatik.uni-leipzig.de/pipermail/openwalnut-dev/
>

-- 
Dipl.-Inf. Christian Heine
c/o Information Technology and Education
ETH-Zentrum, CAB G 66.2
Universitätsstrasse 6                 | Phone: +41 44 632 28 49
CH-8092 Zürich, Switzerland           | http://www.scivis.ethz.ch




More information about the OpenWalnut-Dev mailing list