Should I malloc on Arduino?

March 29, 2011

I’ve been defining an Event class for Arduino processing so I don’t have to think quite so hard about timing loops myself. In the process of doing this, I got the following error:

undefined reference to `operator delete(void*)'

I discovered that the Arduino C++ doesn’t include new() or delete(). (Ok, I guess I shouldn’t be calling it C++….)

I did a quick web search and discovered replacement functions… but then I started thinking.

Why did these get removed from the Arduino C++ variant? On a device as limited as the ATmega328, it makes no sense to malloc() from a pool. Might as well just allocate the variables you want. (Or in my case, allocate an array of variables up front). That way, you know you don’t have a pointer leak that will hose you as you run.

So… I think the answer is no, I shouldn’t malloc on Arduino.

(Edit) Unless, of course, I’m writing a library.

Making git ignore file mode

March 24, 2011

I have recently had to run git on Windows, and things there get all weird because by default git uses file mode as part of its comparison. Because of this, files whose mode have changed show up as different.

Luckily, git has a way around this:

git config core.filemode false