Note that there are some explanatory texts on larger screens.

plurals
  1. POIs this a memory leak? Kernel Resource leak? (C++, parallel studio)
    primarykey
    data
    text
    <p>Background: I'm working on some code to read in data from a file. Examples of data are separated by newlines. Also, there is a meta-level to the data and a semicolon acts as a delimiter to indicate the end of a sequence is reached. The file contains many sequences. I'd like open the file, read in a line of the data and store it as vector, do some stuff with the data, then read in the next line... until the end of the file.</p> <p>The following compiles fine and when run with valgrind on my linux machine, no memory leaks are found. However, when I use the c++ inspector tool in Parallel Studio on my lab's Windows machine it reports to memory related errors in my program, both in this file.</p> <p>A memory leak is reported and seems to stem from the line:</p> <pre><code> ss&gt;&gt;number; </code></pre> <p>And also a kernel resource leak is reported with the following:</p> <pre><code> data.open(filename.c_str()); </code></pre> <p>Can anyone help me to understand why I am getting these errors and what I should do to correct them? I'm not seeing why this is a memory leak and am even less certain about the kernel resource error. Also, if I am doing anything outrageously stupid here, feel free to let me know!</p> <pre><code>class Network; namespace data { static std::string trainfiles[] = { "/home/samurain/htm_check/data_files/train/sequence1.train", "/home/samurain/htm_check/data_files/train/sequence2.train"}; static std::string testfiles[] = { "/home/samurain/htm_check/data_files/train/sequence1.train", "/home/samurain/htm_check/data_files/train/sequence2.train"}; } const char SEQ_DELIM = ';'; struct Example { std::vector&lt;int&gt; stimulus; std::fstream data; bool clear() {stimulus.clear();} bool open_file(std::string &amp; filename) { data.open(filename.c_str()); if (!data) { std::cout &lt;&lt;"error opening file\n"; return false; } std::cout&lt;&lt;"opening file... " &lt;&lt;filename &lt;&lt;" opened \n"; return true; } bool close_file() { std::cout&lt;&lt;"closing file... "; data.close(); data.clear(); std::cout&lt;&lt;"closed\n"; return true; } bool read_next(Network * myNetwork, bool &amp; new_seq) { if (!data) { std::cout&lt;&lt;"file not opened" &lt;&lt;std::endl; return false; } if (data.peek() == SEQ_DELIM) { data.ignore(100,'\n'); myNetwork-&gt;clearStates(); new_seq = true; } int number = 300; //assuming input will be integer values, not set to 0 for debugging purposes std::string line; getline(data, line); if (!data.good()) { std::cout&lt;&lt;"end of file reached" &lt;&lt;std::endl; return false; } std::stringstream ss(line); while (ss) { ss&gt;&gt;number; if (ss.good()) { stimulus.push_back(number); } } return true; }//end read next };//end of Example </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.
    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