Conversation
Use inline functions to keep from repeating code Added a unit test to confirm functions behave as expected fix 2 (minor) bugs
| uint8_t *p = (__brkval == 0 ? (uint8_t *) &__heap_start : __brkval); | ||
|
|
||
| while (*p == STACK_CANARY && (int) p <= SP) | ||
| while (*p == STACK_CANARY && p <= (uint8_t *) SP) |
There was a problem hiding this comment.
fixes a type conversion warning. Probably harmless but distracting
| // | ||
| // Memory addresses | ||
| // | ||
| namespace MU { |
There was a problem hiding this comment.
New namespace "MU". It may not really be necessary, but I thought the library might be heading in that direction with mu_StackCount() and mu_stack_size. I left those alone to ensure these changes are backwards-compatible.
| // | ||
| #include <MemoryUsage.h> | ||
|
|
||
| #include <AUnit.h> |
There was a problem hiding this comment.
Note this new MemoryUsageTest.ino sketch depends on the AUnit library as well as MemoryUsage. Only this sketch's tests need AUnit. Legacy code should still work fine (when AUnit is missing).
| void subSmartPointer(rhaaa &aSample); | ||
| void subConstSmartPointer(const rhaaa &aSample); | ||
|
|
||
| inline void reportMemoryInfo(void) |
There was a problem hiding this comment.
reportMemoryInfo() helps ensure the console text dump is consistent each time it is called. This makes it easier to compare output and recognize changes at each step. (Stack.ino oputput may have added or rearranged lines to make this happen, so comparing output files from earlier runs may see changes)
This is for a backwards-compatible enhancement to the MemoryUsage library.
At this time MemoryUsage is basically a set of macros to collect usage information as text through Serial.print().
I would like to have more direct access to the numerical values. This gives me more flexibility in using the values. With these changes:
(__brkval == 0 ? (int)&__heap_start : (int)__brkval)to get heap end forMEMORY_PRINT_HEAPENDandMEMORY_PRINT_HEAPSIZE) is gathered into single (inline) functions. This helps ensure all code using that value will calculate it the same way.This pull request includes #4 , so if you want both PRs, you only need to review/approve this one.