forked from Archive/PX4-Autopilot
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:
parent
4da2ae2302
commit
1bdad65849
|
@ -62,13 +62,19 @@ public:
|
||||||
unlinkNext(_top);
|
unlinkNext(_top);
|
||||||
|
|
||||||
if (_top->next == nullptr) {
|
if (_top->next == nullptr) {
|
||||||
free((void *)_top->node_name);
|
|
||||||
free(_top);
|
free(_top);
|
||||||
_top = nullptr;
|
_top = nullptr;
|
||||||
_end = 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)
|
void insert(const char *node_name, uORB::DeviceNode *node)
|
||||||
{
|
{
|
||||||
Node **p;
|
Node **p;
|
||||||
|
@ -90,7 +96,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
_end->next = nullptr;
|
_end->next = nullptr;
|
||||||
_end->node_name = strdup(node_name);
|
_end->node_name = node_name;
|
||||||
_end->node = node;
|
_end->node = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,21 +130,6 @@ public:
|
||||||
return nullptr;
|
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
|
Node *top() const
|
||||||
{
|
{
|
||||||
return _top;
|
return _top;
|
||||||
|
@ -150,6 +141,20 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
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 *_top;
|
||||||
Node *_end;
|
Node *_end;
|
||||||
};
|
};
|
||||||
|
|
|
@ -912,9 +912,9 @@ uORB::DeviceMaster::ioctl(device::file_t *filp, int cmd, unsigned long arg)
|
||||||
} else {
|
} else {
|
||||||
// add to the node map;.
|
// add to the node map;.
|
||||||
#ifdef __PX4_NUTTX
|
#ifdef __PX4_NUTTX
|
||||||
_node_map.insert(nodepath, node);
|
_node_map.insert(devpath, node);
|
||||||
#else
|
#else
|
||||||
_node_map[std::string(nodepath)] = node;
|
_node_map[std::string(devpath)] = node;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue