uorb: reduce RAM usage by avoiding string copies

The lifetime of the string is guaranteed because we never delete
DeviceNode objects and the strings in question are already on the heap.

This frees roughly 2.2KB of RAM on Pixracer
This commit is contained in:
Beat Küng 2016-10-18 17:07:40 +02:00 committed by Lorenz Meier
parent 4da2ae2302
commit 1bdad65849
2 changed files with 24 additions and 19 deletions

View File

@ -62,13 +62,19 @@ public:
unlinkNext(_top);
if (_top->next == nullptr) {
free((void *)_top->node_name);
free(_top);
_top = nullptr;
_end = nullptr;
}
}
}
/**
* Insert an element with a unique name
* @param node_name name of the node. This will not be copied, so the caller has to ensure
* the pointer is valid until the node is removed from ORBMap
* @param node
*/
void insert(const char *node_name, uORB::DeviceNode *node)
{
Node **p;
@ -90,7 +96,7 @@ public:
}
_end->next = nullptr;
_end->node_name = strdup(node_name);
_end->node_name = node_name;
_end->node = node;
}
@ -124,21 +130,6 @@ public:
return nullptr;
}
void unlinkNext(Node *a)
{
Node *b = a->next;
if (b != nullptr) {
if (_end == b) {
_end = a;
}
a->next = b->next;
free((void *)b->node_name);
free(b);
}
}
Node *top() const
{
return _top;
@ -150,6 +141,20 @@ public:
}
private:
void unlinkNext(Node *a)
{
Node *b = a->next;
if (b != nullptr) {
if (_end == b) {
_end = a;
}
a->next = b->next;
free(b);
}
}
Node *_top;
Node *_end;
};

View File

@ -912,9 +912,9 @@ uORB::DeviceMaster::ioctl(device::file_t *filp, int cmd, unsigned long arg)
} else {
// add to the node map;.
#ifdef __PX4_NUTTX
_node_map.insert(nodepath, node);
_node_map.insert(devpath, node);
#else
_node_map[std::string(nodepath)] = node;
_node_map[std::string(devpath)] = node;
#endif
}