RobTillaart / RunningAverage

Arduino library to calculate the running average by means of a circular buffer.
MIT License
53 stars 10 forks source link

Memory Usage #34

Closed JCW-74 closed 1 month ago

JCW-74 commented 2 months ago

Hi Rob,

It is unclear how big the arrays can be. I experienced bizarre sketch behaviour when I made them apparently too large (300), obviously overwriting something important. Can you show the limitations?

RobTillaart commented 2 months ago

Thanks for your question. In theory the size is 16 bit so max around 65000. The internal variables like size and count are 16 bit.

In practice it depends on the board you use and possibly the compiler flags.

From my head, the library need to store a float array of N elements and this takes 4N bytes. Furthermore some administrative bytes. 300 elements need therefor at least 1200 bytes which is a lot for an UNO and not so much for an ESP32.

RobTillaart commented 2 months ago

What board do you use?

JCW-74 commented 2 months ago

Hi Rob,Greetings from Australia.That was quick!  Thanks. I am displaying physiological pressures on a UNO.  250 or so is fine for this.  Sent from my iPhoneOn 3 Aug 2024, at 15:01, Rob Tillaart @.***> wrote: What board do you use?

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

JCW-74 commented 2 months ago

Meant to say “bog-standard UNO”.  ESP32 looks good for next project.Sent from my iPhoneOn 3 Aug 2024, at 15:01, Rob Tillaart @.***> wrote: What board do you use?

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

RobTillaart commented 2 months ago

Greetings from Australia. That was quick!

You're welcome,

Can you do a test run and sent the number on 257. If you get strange results there might be an 8 bit overflow somewhere in the code.

JCW-74 commented 2 months ago

Will do, Rob.  Out tonight, on the town. I’ll get back to you tomorrow.Sent from my iPhoneOn 3 Aug 2024, at 17:36, Rob Tillaart @.***> wrote:

Greetings from Australia. That was quick!

You're welcome, Can you do a test run and sent the number on 257. If you get strange results there might be an 8 bit overflow somewhere in the code.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

RobTillaart commented 1 month ago

@JCW-74 Did you find time to do the test with size 257?

RobTillaart commented 1 month ago

@JCW-74 Did you find time to do the test with size 257? (otherwise I close this issue)

JCW-74 commented 1 month ago

Hi Rob. Being new to this I actually responded by email on the same day and not here on GitHub. Using 257 made no difference and so I think it is just a memory overflow issue. I reduced the number of points and it worked fine. Thanks again.

RobTillaart commented 1 month ago

Ok, thanks for the update

RobTillaart commented 1 month ago

As the problem seems solved, I close the issue.