]> git.mxchange.org Git - flightgear.git/commitdiff
Flight-history men usage cap.
authorJames Turner <zakalawe@mac.com>
Tue, 11 Dec 2012 00:10:57 +0000 (00:10 +0000)
committerJames Turner <zakalawe@mac.com>
Tue, 11 Dec 2012 00:10:57 +0000 (00:10 +0000)
Beyond a certain cap (currently 4MB), recycle buckets. With the default sample rate of 1Hz, this gives over 24 hours of history before recycling.

src/Aircraft/FlightHistory.cxx
src/Aircraft/FlightHistory.hxx

index 410d4e582d3152354a5b2cfba0a717215e9c93d5..82304fdd434ca768bfd55d01864a33b5fc52700e 100644 (file)
@@ -51,6 +51,7 @@ FGFlightHistory::~FGFlightHistory()
 
 void FGFlightHistory::init()
 {
+    m_enabled = fgGetNode("/sim/history/enabled", true);
     m_sampleInterval = fgGetDouble("/sim/history/sample-interval-sec", 1.0);
     if (m_sampleInterval <= 0.0) { // would be bad
         SG_LOG(SG_FLIGHT, SG_INFO, "invalid flight-history sample interval:" << m_sampleInterval
@@ -58,6 +59,8 @@ void FGFlightHistory::init()
         m_sampleInterval = 1.0;
     }
     
+  // cap memory use at 4MB
+    m_maxMemoryUseBytes = fgGetInt("/sim/history/max-memory-use-bytes", 1024 * 1024 * 4);
     m_weightOnWheels = NULL;
 // reset the history when we detect a take-off
     if (fgGetBool("/sim/history/clear-on-takeoff", true)) {
@@ -82,7 +85,9 @@ void FGFlightHistory::reinit()
 
 void FGFlightHistory::update(double dt)
 {
-    SG_UNUSED(dt); // we care about sim-time, not frame-time
+    if ((dt == 0.0) || !m_enabled->getBoolValue()) {
+        return; // paused or disabled
+    }
     
     if (m_weightOnWheels) {
         
@@ -100,7 +105,14 @@ void FGFlightHistory::update(double dt)
 
 void FGFlightHistory::allocateNewBucket()
 {
-    SampleBucket* bucket = new SampleBucket;
+    SampleBucket* bucket = NULL;
+    if (!m_buckets.empty() && (currentMemoryUseBytes() > m_maxMemoryUseBytes)) {
+        bucket = m_buckets.front();
+        m_buckets.erase(m_buckets.begin());
+    } else {
+        bucket = new SampleBucket;
+    }
+    
     m_buckets.push_back(bucket);
     m_validSampleCount = 0;
 }
@@ -164,3 +176,8 @@ void FGFlightHistory::clear()
     m_validSampleCount = SAMPLE_BUCKET_WIDTH;
 }
 
+size_t FGFlightHistory::currentMemoryUseBytes() const
+{
+    return sizeof(SampleBucket) * m_buckets.size();
+}
+
index 29b0fb1221a4fc977cf47450fed0b52403af8849..38e3d44f2f6fe9ad7c4e29ef40953cc254933d38 100644 (file)
@@ -94,12 +94,17 @@ private:
     unsigned int m_validSampleCount;
     
     SGPropertyNode_ptr m_weightOnWheels;
+    SGPropertyNode_ptr m_enabled;
+  
     bool m_lastWoW;
-    
+    size_t m_maxMemoryUseBytes;
+  
     void allocateNewBucket();
     
     void clear();
     void capture();
+  
+    size_t currentMemoryUseBytes() const;
 };
 
 #endif
\ No newline at end of file