malloc in embedded systems [duplicate]

2019-04-07 23:31发布

This question already has an answer here:

I am working with an embedded system. The application is running on AT91SAMxxxx and cortex m3 lpc17xxx. I am looking into dynamic memory allocation as it would dramatically change the face of the application (and give me more Power).

I think the my only real route is to set out an area of memory for a heap and design a tailored malloc that best fits (pun) my purpose.

When looking at different algorithms for memory allocation you cant not stumble upon Doug Lea's malloc. I take it this has been used in embedded systems such as mine where there is no OS and tailored versions of say the sbrk() function have been provided to accomplish this. I'm trying to find good examples of this being achieved to maybe try a proof of concept before I jump into writing my own.

Is it possible to use dlmalloc in a system such as mine ?

If yes can anyone point me to a relevant resource ? (not found many that help me)

Is it better to go and write my own malloc that is tailored to my needs ?

And apologies most of my research so far has been on designing a malloc not using doug's which is a different challenge. Guess I'm trying to find out is looking into this route in more depth a waste of time.

Edit:

moral of the story: looking at dlmalloc in my case pointless.

1条回答
手持菜刀,她持情操
2楼-- · 2019-04-08 00:19

For your situation your own implementation of malloc or dlmalloc is definately possible, but not advisable.

On very low level embedded systems, bare metal MCU's etc, using malloc is pointless.

You will be running your app and only your app on them, you know how much memory you have and can use, and you are fully able to tailor your program to fit such needs. With malloc you save memory, but that is pointless here. If your program at its highest memory usage does not exceed the memory available on the device, and your program is the only one running, there is no reason to use malloc, and no reason to let any memory go unused.

tl;dr Its possible but exceedingly pointless.

查看更多
登录 后发表回答