Skip to content

Conversation

@SilentButeo2
Copy link

During debug I hit the _sbrk_r() function, but the incr parameter was 0. Callstack points out it is mallinfo() that initiates the call.
Because the current code goes into a critical section (ST) or suspends all tasks (NXP) but doesn't change anything in between, this is optimized away.

Unless the _sbrk_r is also used do some limit checks, I think this adjustment is safe.
Tested with an ST setup.

Copy link
Owner

@DRNadler DRNadler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Some questions though:

  1. How often is mallinfo called? Is this really worth adding code to optimize?
  2. If so, please add a comment about WHY this is worthwhile optimizing ie Happens when called from mallinfo twice per week
  3. Didn't you mean to cast the return value to (void*), not (char*)?
    Thanks again,
    Best Regards, Dave

@StefanBalt
Copy link

1. How often is mallinfo called? Is this really worth adding code to optimize?

I do not know why mallinfo() should be relevant as only sbrk() is changed.

2. If so, please add a comment about WHY this is worthwhile optimizing ie _Happens when called from mallinfo twice per week_

I think mallinfo() does not matter here.
sbrk() is called any time an allocation does not fit into the memory previously requested via sbrk().
Typically this happens a lot at the start of the program and fewer the longer it runs.

I am not sure if this optimization is needed but it seems cheap with only a few lines added.

3. Didn't you mean to cast the return value to (void*), not (char*)?

All returns in sbrk() cast to (char*), so I guess this is for consistency reasons.

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 this pull request may close these issues.

4 participants