Click here to Skip to main content
15,887,416 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: GMail Spam Pin
Slacker00725-Feb-23 11:27
professionalSlacker00725-Feb-23 11:27 
PraiseThis doesn't seem like much... Pin
honey the codewitch25-Feb-23 9:30
mvahoney the codewitch25-Feb-23 9:30 
GeneralRe: This doesn't seem like much... Pin
Mike Hankey25-Feb-23 10:15
mveMike Hankey25-Feb-23 10:15 
GeneralRe: This doesn't seem like much... Pin
jmaida25-Feb-23 17:22
jmaida25-Feb-23 17:22 
GeneralRe: This doesn't seem like much... Pin
honey the codewitch25-Feb-23 22:01
mvahoney the codewitch25-Feb-23 22:01 
GeneralRe: This doesn't seem like much... Pin
jmaida26-Feb-23 9:24
jmaida26-Feb-23 9:24 
QuestionUsing dynamic memory in microcontrollers Pin
CPallini25-Feb-23 5:06
mveCPallini25-Feb-23 5:06 
AnswerRe: Using dynamic memory in microcontrollers Pin
honey the codewitch25-Feb-23 5:15
mvahoney the codewitch25-Feb-23 5:15 
If you mean things like malloc(), yes and no.

Heap fragmentation is a constant battle because you're dealing with very little SRAM.

Therefore, you need to be strategic about your allocations. Allocate, use, toss, as quickly as possible, OR allocate a large buffer initially, and then work from that.

I'll assume C++ below, though the above principles apply to things like C as well.

One caveat is you don't usually have debugging facilities, so it can be difficult to find leaks. Judicious use of the RAII pattern should take care of this. I usually delete copy constructors and implement move constructors for most of my classes that allocate to avoid casual allocations.

You'll probably want to avoid using The STL since they didn't really consider constrained memory environments when they made it - it whips the heap with a lot of little allocations. It *is* possible to cajole The STL into using a custom allocation scheme but there's also the issue of The STL not always being fully available, such as on 8-bit platforms, so I usually avoid it unless I'm targeting a particular platform and I know it supports it, if that makes sense.

The bottom line is: Be careful, be strategic, and you'll be okay.
To err is human. Fortune favors the monsters.

GeneralRe: Using dynamic memory in microcontrollers Pin
CPallini25-Feb-23 5:27
mveCPallini25-Feb-23 5:27 
GeneralRe: Using dynamic memory in microcontrollers Pin
honey the codewitch25-Feb-23 7:29
mvahoney the codewitch25-Feb-23 7:29 
GeneralRe: Using dynamic memory in microcontrollers Pin
CPallini25-Feb-23 7:42
mveCPallini25-Feb-23 7:42 
GeneralRe: Using dynamic memory in microcontrollers Pin
honey the codewitch25-Feb-23 7:54
mvahoney the codewitch25-Feb-23 7:54 
GeneralRe: Using dynamic memory in microcontrollers Pin
jschell28-Feb-23 5:39
jschell28-Feb-23 5:39 
GeneralRe: Using dynamic memory in microcontrollers Pin
CPallini28-Feb-23 10:03
mveCPallini28-Feb-23 10:03 
AnswerRe: Using dynamic memory in microcontrollers Pin
OriginalGriff25-Feb-23 5:52
mveOriginalGriff25-Feb-23 5:52 
GeneralRe: Using dynamic memory in microcontrollers Pin
CPallini25-Feb-23 6:22
mveCPallini25-Feb-23 6:22 
GeneralRe: Using dynamic memory in microcontrollers Pin
honey the codewitch25-Feb-23 22:21
mvahoney the codewitch25-Feb-23 22:21 
AnswerRe: Using dynamic memory in microcontrollers Pin
Ron Anders25-Feb-23 6:07
Ron Anders25-Feb-23 6:07 
GeneralRe: Using dynamic memory in microcontrollers Pin
CPallini25-Feb-23 6:17
mveCPallini25-Feb-23 6:17 
GeneralNo sea too high Pin
RickZeeland25-Feb-23 2:52
mveRickZeeland25-Feb-23 2:52 
GeneralRe: No sea too high Pin
BillWoodruff25-Feb-23 4:45
professionalBillWoodruff25-Feb-23 4:45 
GeneralRe: No sea too high Pin
RickZeeland25-Feb-23 6:46
mveRickZeeland25-Feb-23 6:46 
QuestionRe: No sea too high Pin
Eddy Vluggen25-Feb-23 11:28
professionalEddy Vluggen25-Feb-23 11:28 
AnswerRe: No sea too high Pin
RickZeeland25-Feb-23 18:48
mveRickZeeland25-Feb-23 18:48 
GeneralRe: No sea too high Pin
Eddy Vluggen26-Feb-23 7:23
professionalEddy Vluggen26-Feb-23 7:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.