New Data Types

Moderator: Benj

Post Reply
dbasnett
Posts: 125
Joined: Mon Aug 15, 2011 1:54 pm
Has thanked: 8 times
Been thanked: 11 times
Contact:

New Data Types

Post by dbasnett »

It is my understanding that v5 will contain a single bit (boolean? T/F) data type. If that is true I can see how it will save memory, but I wonder if the code will be longer? In pseudo-code:

foo as byte - used for T/F

if foo then - how much code to test T/F
else
endif

foo as bit- used for T/F

if foo then - how much code to test T/F
else
endif


My question boils down to how many instructions does it take, in both cases, to check for true / false. If there isn't a difference, or checking a single bit is shorter, then the question is moot. If checking a single bit takes more instructions then a choice can be made based on requirements.

User avatar
Steve
Matrix Staff
Posts: 3418
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: New Data Types

Post by Steve »

We've not done much testing for this, and it will heavily depend on the program itself, the compiler toolchain used and any optimisations present.

I did a quick test and had the following results for a very simple program for an 8-bit PICmicro using BoostC:

using bools:

Code: Select all

RAM available:368 bytes, used:36 bytes (9.8%), free:332 bytes (90.2%), 
Heap size:332 bytes, Heap max single alloc:110 bytes
ROM available:4096 words, used:82 words (2.1%), free:4014 words (97.9%)
using bytes:

Code: Select all

RAM available:368 bytes, used:37 bytes (10.1%), free:331 bytes (89.9%), 
Heap size:331 bytes, Heap max single alloc:110 bytes
ROM available:4096 words, used:81 words (2.0%), free:4015 words (98.0%)
So it looks like you are correct - you will save RAM. But this may be at the cost of ROM.

But including the BOOL type in Flowcode is not just about saving memory. The biggest benefit for me is that it makes the code tighter and better to read.

dbasnett
Posts: 125
Joined: Mon Aug 15, 2011 1:54 pm
Has thanked: 8 times
Been thanked: 11 times
Contact:

Re: New Data Types

Post by dbasnett »

Using Bools - RAM used = 36 bytes ROM Used = 82 words

Using Bytes - RAM used = 37 bytes ROM Used = 81 words

Bool diff. RAM used = -1 bytes ROM Used = +1 words

That is good information. We can certainly make an informed choice based on the requirement.

If I need to save RAM, use bool. If I need to save ROM, use byte. (in both cases there is an assumption that the other is not an issue)

If neither is of concern then bool is the logical ;) choice.

I can hardly wait for the release!

saschech@gmx.de
Posts: 714
Joined: Wed Jan 31, 2007 12:41 pm
Has thanked: 1 time
Been thanked: 26 times
Contact:

Re: New Data Types

Post by saschech@gmx.de »

Hello Team

Work`s "dbasnett" with the V5 beta?

Regards Wolfgang

User avatar
Steve
Matrix Staff
Posts: 3418
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: New Data Types

Post by Steve »

No - the figures were from an internal test.

We have had an advanced BETA now for a few weeks, but we are yet to distribute it widely.

Post Reply