Skip to content

Fix fileBuffer RAM allocation #20

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

Closed
adamgarbo opened this issue Mar 31, 2021 · 5 comments · Fixed by #21
Closed

Fix fileBuffer RAM allocation #20

adamgarbo opened this issue Mar 31, 2021 · 5 comments · Fixed by #21

Comments

@adamgarbo
Copy link
Contributor

adamgarbo commented Mar 31, 2021

Hi @PaulZC,

As discussed earlier, we'll need to fix how the .createFileBuffer() function allocates RAM. At present, if the system makes multiple calls to .begin(), RAM usage will eventually exceed the available memory (e.g. a 16 KB file buffer will consume all 384 KB RAM on the Artemis after 24 sleep/wake cycles). In actuality, this seems to occur at about the 14th sleep/wake cycle, which causes an immediate hard reset of the processor.

Offending line of code:

ubxFileBuffer = new uint8_t[fileBufferSize]; // Allocate RAM for the buffer

Cheers,
Adam

@PaulZC
Copy link
Collaborator

PaulZC commented Apr 1, 2021

Thanks for finding this Adam!
Corrected in this commit.
Please give Example26 a try.

@adamgarbo
Copy link
Contributor Author

Thanks, Paul!

Will try it out this morning. Can you clarify what you mean by "End will stop all automatic message processing and free (nearly) all used RAM."? Is there still some RAM that will be lost after each .begin() call? Thinking about long-term (1-year) deployments of the code.

Cheers,
Adam

@PaulZC
Copy link
Collaborator

PaulZC commented Apr 1, 2021

Hi Adam,
The memory leak - from multiple calls to .begin - should be completely fixed.
.end is optional but you can use it to deallocate (delete) all of the allocated RAM except payloadCfg. (That's why I use the word "nearly"!).
Cheers,
Paul

@adamgarbo
Copy link
Contributor Author

Thanks, Paul!

I've been letting the code run all morning and am currently up to 40 sleep/wake cycles with a 16 KB buffer and no issues!

Cheers,
Adam

@PaulZC
Copy link
Collaborator

PaulZC commented Apr 1, 2021

Jolly good!
Have a nice Easter!
:-)

@PaulZC PaulZC linked a pull request Apr 1, 2021 that will close this issue
@PaulZC PaulZC closed this as completed in #21 Apr 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants