Pages: [1]   Go Down
Author Topic: Memory Management  (Read 547 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
Jr. Member
**
Karma: 2
Posts: 90
It was like it when I found it
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can I use alloc() to load a whole class into memory? (I guess I mean a whole object based on a class), and then use free() afterwards?

I’ve written a project based on a dozen or more library’s I’ve written. I’ve estimated the memory footprint of some of the larger objects to be about 500 bytes (I do quite a bit of string manipulation which seems to take up a lot of space). Several of those objects are used once and once only during the ‘setup()’ part of the sketch. My (limited) understanding is that this memory once allocated stays there permanently, even if the object doesn’t get used again, is this correct?

My application is running (very) low on memory, is there a way of freeing up this memory after the object has done what it’s got to do?

Also, is there a tutorial on memory management directed specifically to the arduino? I’ve tried to read-up on this subject, but a lot of the general C and c++ stuff I read is often different from what I read on this forum.

Mike
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't know your code and some libs automatically create a static instance, so it depends on the lib.

If you split your application in several functions that are to be called sequentially in loop() that may lower the footprint. If you want us to help Please share your code.

Rob
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Germany
Offline Offline
Edison Member
*
Karma: 133
Posts: 1447
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

so far I did not use alloca or malloc for my arduino programs, but this should apply directly to the arduino environment:
http://www.nongnu.org/avr-libc/user-manual/group__alloca.html
http://www.nongnu.org/avr-libc/user-manual/malloc.html

alloca() does not require free()
malloc() requires a call to free()

Oliver
Logged

UK
Offline Offline
Jr. Member
**
Karma: 2
Posts: 90
It was like it when I found it
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, that 2nd link was particularly informative.

Most of my librarys are large and require extra hardware, so I'm niot sure ther'd be much to gain by posting the whole thing here.

Thanks guys
Logged

Pages: [1]   Go Up
Jump to: