Pages: [1]   Go Down
Author Topic: Can I use the "new" C++ memory features?  (Read 688 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sometimes the compiler seems to be C++, and other times its like C. It knows about "class" and doesn't seem to care where variables are declared (like C++), but when I try to allocate memory dynamically:

   char *stuff = new char[10] ;

it gives me a compiler error that seems to suggest that it isn't compiling as c++, even though the file extension is cpp.

Is there a way to turn on 'new', or do I need to allocate memory the old fashioned way?

Thanks!
Mark
Logged

London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Arduino does use C++ but the AVR-GCC compiler used has some restrictions related to its use on an embedded platform.

New and delete were not supported the last time I looked at the compiler spec, but malloc and free are so you can make your own if you want, see this thread: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1230935955

with only a few k of RAM be very careful about allocating dynamic memory – its easy to run out.

Have fun!
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks!
It looks like its back to the drawing board.
Logged

Pages: [1]   Go Up
Jump to: