Go Down

Topic: 2D dynamic boolean array (Read 2 times) previous topic - next topic


A boolean still has 8 bits.

(Each boolean variable occupies one byte of memory.)

That boolean has enough room to hold information about 8 squares. Proper indexing would allow you to store information about the room in a 1D array, and in less space, if stored bit-by-bit.


Dec 31, 2010, 08:52 pm Last Edit: Dec 31, 2010, 08:53 pm by mrmeval Reason: 1


The bitarray library in the last two links might be worthwhile to look at the source code, it's not an Arduino library.
If it was designed by man it can be repaired by man.



I am very reluctant to use dynamic memory allocation in any embedded system that I expect to run forever.  Why do I have misgivings?  Lack of garbage collection in the standard library function malloc(). That's why.

It is possible to allocate and deallocate memory  (repeatedly) in such a way that there is enough memory in the heap to do the job but it is fragmented so that that not enough contiguous memory is available to finish it.

I mean, if the application is supposed to do something and quit, that's one thing, but if it is supposed to run forever and you don't know ahead of time how much memory you actually need, then, you are really, really (really) asking for trouble.  For simple cases, you might convince yourself that such fragmentation will not occur, but...

That's just an opinion (my opinion), and it's worth exactly what you want it to be worth.

not to mention that even if you did everything right it is still really tough to figure out just how much memory you are allocating.  And if you do know, why does it need to be dynamic?

[The robot's] task is mapped a "room". He use array to save information about room as square site.

They make SD card shields for arduino and it sounds like you may need to store a lot of data (>8k).  It may be worth it to think of a linear data format that can be parsed later and store it to an SD card since they are cheap, easy, and give virtually unlimited storage.


Dec 31, 2010, 10:33 pm Last Edit: Dec 31, 2010, 10:35 pm by kamtar Reason: 1
No I didnt use arduino board. I made own board but I can use bluetooh for send data to PC or any device ... I use this robot in "test arena" c. 4x4square and for test the functionality of the algorithm in larger areas can be used bluetooh.


ah i see.  In that case you can go to town with malloc() (in the pc's code). ;D

Go Up