B4R Question Occupation of Variables in RAM memory

Gerardo Tenreiro

Active Member
Licensed User
Hello Group

I have an application with a large structure that stores information in RAM for a period of about 4 seconds. I want to store the information at intervals of 20 to 40 ms.
The data structure is as follows:

The problem I'm seeing is that the BOOLEAN variables take up 8 bits instead of 1 bit. They should take up one bit since a BOOLEAN is either a 1 or a 0.
How can I find out how much the variables take up in memory?

Thank you very much.
 

Daestrum

Expert
Licensed User
Longtime User
Maybe look at putting your boolean values in a C struct, where they can be 1 bit
B4X:
struct Flags {
    unsigned char flag1 : 1;
    unsigned char flag2 : 1;
    unsigned char flag3 : 1;
    unsigned char flag4 : 1;
    unsigned char flag5 : 1;
    unsigned char flag6 : 1;
    unsigned char flag7 : 1;
    unsigned char flag8 : 1;
 };
 
Upvote 0

Gerardo Tenreiro

Active Member
Licensed User
I changed the structure from BOOLEAN to BYTE by grouping 8 BOOLEANs into a BYTE, and the size improved considerably.
The structure is now as follows:

Now I need to perform the BOOLEAN to BYTE conversion steps, but it's a workaround.

I still don't know how to measure the occlusion of variables in the processor's RAM. I don't know if B4R has any instructions that allow this.

Thank you very much.
 
Upvote 0

Gerardo Tenreiro

Active Member
Licensed User
AvailableRAM
StackBufferUsage
This is what I'm using, but the results are confusing. The ratio of RAM used isn't linear with the number of variables I declare.
Also, in the application, the "AvailableRAM" result changes depending on the time.

I've attached a screenshot of the LOGGER where I see the results.


Thank you very much.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…