-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
rework sensor instantiation to saves memory by removing the static allocation #8054
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request replaces static allocation of the bsecState
buffer with dynamic allocation using malloc()
to save 238 bytes of static memory. The change moves the buffer allocation from a class member to local variables within the methods that use it.
Key Changes
- Removed static
bsecState
array from BME680Sensor class member variables - Added dynamic allocation with
malloc()
inloadState()
andupdateState()
methods - Added proper error handling and memory cleanup with
free()
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
BME680Sensor.h | Removes static bsecState array declaration from class members |
BME680Sensor.cpp | Implements dynamic allocation with malloc/free in loadState() and updateState() methods |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
A much larger portion of static allocation could be saved if all the sensor instances are declared as pointer and allocated in heap space during init. Then no changes in this BSEC sensor class are required, e.g. see here:
|
true, had a look at EnvironmentTelemetry.cpp and it looks like there is a lot more possibility for optimizion. looked a bit deeper and I think the I2C device handling overall needs some work. |
1fe2139
to
16bdf14
Compare
have working code that elimenates the need for moved over 4 sensors to show case the idea, but want some feedback before doing all of them. I dont see that we get memory fragmentation problem with this code, since the only cases where we delete / free something is when the sensor failed it initialisation. tested this with a BMP-280 connected to a Heltec V2.1 please review and give feedback if this code is something that can be merged (will migrate the other sensors then). |
the goal is to only instantiate sensors that are pressend to save memory. side effacts: - easyer sensor integration (less C&P code) - nodeTelemetrySensorsMap can be removed when all devices are migrated
16bdf14
to
3bb927e
Compare
RAM -816 Flash -916
did a second batch of sensors RAM -816 |
RAM -192 Flash -60
Flash -112
not sure what magic is used but it works
Tagging @oscgonfer for visibility |
The PR now covers all sensors that where allocated staticly in Total saved: RAM -2160 we will save CPU cycles too since we do a lot less some sensors like the INA ones are part of Ready for review. |
rework I2C sensor init.
The goal is to only instantiate sensors that are pressend to save memory.
Side effacts:
🤝 Attestations