Failed to free stack memory

I have the following loop that appears from the current C ++ parallel queue, from the implementation here. https://juanchopanzacpp.wordpress.com/2013/02/26/concurrent-queue-c11/

while (!interrupted)
{
    pxData data = queue->pop(); 
    if (data.value == -1)
    { 
        break; // exit loop on terminating condition
     }
    usleep(7000); // stub to simulate processing
}

I am viewing memory history using System Monitor in CentOS7. I am trying to free the memory occupied by the queue after reading the value from the queue. However, since the following while loop is working, I do not see the memory usage decreasing. I checked that the queue length is decreasing.

However, it crashes when -1 is encountered, and the loop ends. (the program is still working) But I can’t do this, because where this happens, I want to do intensive processing.

Question : Why is the memory occupied by the data not freed? (in accordance with the system monitor). Shouldn't the allocated stack memory be free if the variable goes out of scope?

The structure is defined as follows and is filled at the beginning of the program.

typedef struct pxData
{
  float value; // -1 value terminates the loop
  float x, y, z;
  std::complex<float> valueData[65536];
} pxData;

It is filled with ~ 10,000 pxData, which roughly corresponds to 5 GB. The system has only ~ 8 GB. Therefore, it is important that the memory is free to perform other processing on the system.

+4
source share
2 answers

There are a few things here.

Virtual memory

-, , , "" 5 , , 3 . , 5 1 "" , 4 , . , " ", . , , RSS "" . "5 ", , - , .

- . , , malloc new , . , , , . , , , 90% , :

[program|------------------unused-------------------|pxData]

, , free delete - , . , , , "" (.. ). ++ , "" . , , , :

[program|------------------unused--------------------------]

:

[program]

, .

"" , , "reverse", .. , .

- mmap, , , , Linux , "". , mallopt(3) M_MMAP_THRESHOLD . , . , , , .

+6

++ operator delete, ( operator new) . ++ new malloc delete free.

( Linux, )

malloc ( ::operator new) , mmap (2), free ( ::operator delete) malloc ( new)

, (, /proc/, . proc (5)...), , , "" ( malloc new)

++ . , std::map std::vector ( std::deque) new delete .


, . struct pxData 65536 valueData, std::vector,

  std::vector<std::complex<float>> valueData;

. , valueData.reserve(somesize); / valueData.resize(somesize); / valueData.push_back(somecomplexnumber); .....

+3

Source: https://habr.com/ru/post/1620061/


All Articles