mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-21 09:13:33 +08:00
BlockParam: remove _extern_address and create a new class BlockParamExt for this
In most cases, _extern_address was unused, thus wasting cycles & RAM. This adds a separate class BlockParamExt with the field and uses it in ekf2_main Frees roughly 0.5KB of RAM on Pixracer
This commit is contained in:
@@ -77,21 +77,45 @@ class BlockParam : public BlockParamBase
|
||||
{
|
||||
public:
|
||||
BlockParam(Block *block, const char *name,
|
||||
bool parent_prefix = true, T *extern_address = NULL);
|
||||
bool parent_prefix = true);
|
||||
BlockParam(const BlockParam &) = delete;
|
||||
BlockParam &operator=(const BlockParam &) = delete;
|
||||
|
||||
T get();
|
||||
void commit();
|
||||
void set(T val);
|
||||
void update();
|
||||
void update() override;
|
||||
virtual ~BlockParam();
|
||||
protected:
|
||||
T _val;
|
||||
T *_extern_address;
|
||||
};
|
||||
|
||||
typedef BlockParam<float> BlockParamFloat;
|
||||
typedef BlockParam<int> BlockParamInt;
|
||||
|
||||
|
||||
/**
|
||||
* Same as BlockParam, but in addition with a pointer to an external field that will be
|
||||
* set to the value of the parameter.
|
||||
* (BlockParam should be prefered over this)
|
||||
*/
|
||||
template <class T>
|
||||
class BlockParamExt : public BlockParam<T>
|
||||
{
|
||||
public:
|
||||
BlockParamExt(Block *block, const char *name,
|
||||
bool parent_prefix, T &extern_val);
|
||||
BlockParamExt(const BlockParamExt &) = delete;
|
||||
BlockParamExt &operator=(const BlockParamExt &) = delete;
|
||||
|
||||
void set(T val);
|
||||
void update() override;
|
||||
virtual ~BlockParamExt();
|
||||
protected:
|
||||
T &_extern_val;
|
||||
};
|
||||
|
||||
typedef BlockParamExt<float> BlockParamExtFloat;
|
||||
typedef BlockParamExt<int> BlockParamExtInt;
|
||||
|
||||
} // namespace control
|
||||
|
||||
Reference in New Issue
Block a user