|
From: <tf...@us...> - 2008-04-30 01:17:52
|
Revision: 243
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=243&view=rev
Author: tfoote
Date: 2008-04-29 18:17:58 -0700 (Tue, 29 Apr 2008)
Log Message:
-----------
adding a max length to the linked list to prevent unbounded memory usage
Modified Paths:
--------------
pkg/trunk/libTF/include/libTF/Quaternion3D.h
pkg/trunk/libTF/src/simple/Quaternion3D.cpp
Modified: pkg/trunk/libTF/include/libTF/Quaternion3D.h
===================================================================
--- pkg/trunk/libTF/include/libTF/Quaternion3D.h 2008-04-30 00:56:19 UTC (rev 242)
+++ pkg/trunk/libTF/include/libTF/Quaternion3D.h 2008-04-30 01:17:58 UTC (rev 243)
@@ -53,6 +53,7 @@
public:
static const int MIN_INTERPOLATION_DISTANCE = 5; //Number of nano-seconds to not interpolate below.
+ static const unsigned int MAX_LENGTH_LINKED_LIST = 1000000; // Maximum length of linked list, to make sure not to be able to use unlimited memory.
// Storage class
class Quaternion3DStorage
{
@@ -155,8 +156,8 @@
data_LL* first;
data_LL* last;
+ unsigned int list_length;
-
};
Modified: pkg/trunk/libTF/src/simple/Quaternion3D.cpp
===================================================================
--- pkg/trunk/libTF/src/simple/Quaternion3D.cpp 2008-04-30 00:56:19 UTC (rev 242)
+++ pkg/trunk/libTF/src/simple/Quaternion3D.cpp 2008-04-30 01:17:58 UTC (rev 243)
@@ -42,7 +42,8 @@
Quaternion3D::Quaternion3D(unsigned long long max_cache_time):
max_storage_time(max_cache_time),
first(NULL),
- last(NULL)
+ last(NULL),
+ list_length(0)
{
pthread_mutex_init( &linked_list_mutex, NULL);
@@ -355,7 +356,6 @@
void Quaternion3D::insertNode(const Quaternion3DStorage & new_val)
{
-
data_LL* p_current;
data_LL* p_old;
@@ -417,6 +417,10 @@
}
+
+ // Record that we have increased the length of th elist
+ list_length ++;
+
};
void Quaternion3D::pruneList()
@@ -432,7 +436,7 @@
//While time stamps too old
- while (p_current->data.time + max_storage_time < current_time)
+ while (p_current->data.time + max_storage_time < current_time || list_length > MAX_LENGTH_LINKED_LIST)
{
// cout << "Age of node " << (double)(-p_current->data.time + current_time)/1000000.0 << endl;
// Make sure that there's at least two elements in the list
@@ -446,6 +450,7 @@
delete p_current;
p_current = last;
// cout << " Pruning Node" << endl;
+ list_length--;
}
else
break;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|