Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : MMBasic 4.4 Beta 4
Page 3 of 3 | |||||
Author | Message | ||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
That's great Geoff, that's exactly what I was seeing that stopped me using PWM for servo control. Greg |
||||
MicroBlocks Guru Joined: 12/05/2012 Location: ThailandPosts: 2209 |
When working with strings, especially many small ones it is known to be slow in almost any language. C# has a nice solution that can be a good candidate for MMBasic. The full capabilities are not necessary but if a few methods are implemented it can speed up certain type of algorithms that use strings. The stringbuilder class is described here: http://msdn.microsoft.com/en-us/library/system.text.stringbu ilder.aspx For use in MMBasic i think the necessary methods would be. Init(Capacity) Clear() Sets the length to zero, capacity unchanged. EnsureCapacity(NeededCapacity) Append(a$) Insert(index,value|values$) Remove(startIndex,length) Replace(startIndex, value|values$) On a lower level it is just a array of bytes that is being allocated one time. For a game you could build a map, for data communication you could load a template and fill in the 'blanks' and send it as one 'blob'. You could have a screen template that you update with data and copy it to the screen in one time. When logging you can append values to it and when capacity is reached dump it to an SD card. There would be many uses for it, and it can be lightning fast as no recurring memory allocations have to be done. Microblocks. Build with logic. |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3802 |
Maybe some snags: 1. very low memory makes any solution awkward 2. languages such as C# use a GC (garbage collector), but not MMBasic (and see item 1) Item 1 tends to make fragmentation a serious problem even with a GC... John |
||||
MicroBlocks Guru Joined: 12/05/2012 Location: ThailandPosts: 2209 |
With MMBasic the underlying C does not have garbage collection, and that is certainly in a microcontroller that needs an uninterrupted program flow critical. You don't want the CG kicking in at some uncontrollable time. The StringBuilder in C# is great i find myself using it all the time, especially for appending. You instantiate it with the capacity you want and then fill it with values. It goes incredible fast as no reallocation of memory is necessary. Even on a PC with dual core and running at 2Ghz it makes a noticable difference compared with normal string concatenation. A simpler stringbuilder equivalent in MMBasic would need only a little bit of memory management. Microblocks. Build with logic. |
||||
Page 3 of 3 |
Print this page |