Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 21:42 27 Nov 2024 Privacy Policy
Jump to

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: Australia
Posts: 1329
Posted: 12:03am 15 Jun 2013
Copy link to clipboard 
Print this post

  Geoffg said   BTW I discovered a bug in the PWM code which meant that the PWM duty cycle only had a resolution of 1%. It should be 0.1% and that will be fixed in the next beta.Geoff

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: Thailand
Posts: 2209
Posted: 10:06am 15 Jun 2013
Copy link to clipboard 
Print this post

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.
Edited by TZAdvantage 2013-06-16
Microblocks. Build with logic.
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3802
Posted: 12:20pm 15 Jun 2013
Copy link to clipboard 
Print this post

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...

JohnEdited by JohnS 2013-06-16
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 09:38pm 15 Jun 2013
Copy link to clipboard 
Print this post

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


To reply to this topic, you need to log in.

© JAQ Software 2024