Skip to main content
Zainka
Associate III
September 1, 2012
Solved

malloc library - _sbrk problem

  • September 1, 2012
  • 2 replies
  • 1032 views
Posted on September 02, 2012 at 00:47

I was trying to use malloc in a project  which has been ported from an other platform. I get the message that...

_sbrk

 ... is undefined. This is used by _sbrk_r which again is used by malloc. I found no solution herein but looked at the following at http://embdev.net/topic/129753   I am not very familiar to this so a little help would do. I can create the function if needed, no prob. but I find it likely that this has already been solved somehow for stm32fxx devices and i rather like the idea to have something dedicated instead for me trying to implement this myself.

FYI : The heap size is set to 16KB

Breg

Vidar

#malloc-_sbrk #dynamic-allocation---just-say-no
    This topic has been closed for replies.
    Best answer by Tesla DeLorean
    Posted on September 02, 2012 at 02:44

    Dynamic memory allocation in embedded systems is very problematic, basically revolving around memory leakage, heap fragmentation and what to do when the allocation fails.

    Consider your options to statically allocate resources, or fixed pools.

    http://en.wikipedia.org/wiki/Memory_management#Fixed-size-blocks_allocation

    2 replies

    Tesla DeLorean
    Tesla DeLoreanBest answer
    Guru
    September 2, 2012
    Posted on September 02, 2012 at 02:44

    Dynamic memory allocation in embedded systems is very problematic, basically revolving around memory leakage, heap fragmentation and what to do when the allocation fails.

    Consider your options to statically allocate resources, or fixed pools.

    http://en.wikipedia.org/wiki/Memory_management#Fixed-size-blocks_allocation

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    Andrew Neil
    Super User
    September 3, 2012
    Posted on September 03, 2012 at 13:59

    ''I can create the function if needed, no prob. but I find it likely that this has already been solved somehow for stm32fxx devices...''

     

    As clive1 suggests, the usual ''solution'' for embeded systems is to

    not

       use dynamic memory allocation!

    Your time may be better spent adjusting the code to a more ''embedded-friendly'' approach...

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.