Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solving the problem of excessive space usage by boolean arrays #1

Open
xaxys opened this issue Dec 2, 2023 · 2 comments
Open

Solving the problem of excessive space usage by boolean arrays #1

xaxys opened this issue Dec 2, 2023 · 2 comments

Comments

@xaxys
Copy link
Owner

xaxys commented Dec 2, 2023

We have a structure like this

struct RovExdataLeakageData[6] {
    bool<48> leakage [order="big"];
}

It contains 48 bool bit to indicate where each sensor detects leackage or not.

However, it will be translated as below

// Struct: RovExdataLeakageData [6] {1 fields}
struct RovExdataLeakageData {
    // [0, 6) NormalField: bool<48> leakage[6]
    bool leakage[48];
};

This structure will take up to 48 Byte space in memory, which is unacceptable for embedded device.

Could we figure out a solution to reduce the consumption of memory?

@xaxys xaxys added this to bubbler Dec 2, 2023
@xaxys xaxys converted this from a draft issue Dec 2, 2023
@xaxys
Copy link
Owner Author

xaxys commented Dec 2, 2023

Spread the array into bit field with a option to control it? (e.g. [unfold = true])

It seems impossible to use bit field, since there is no such thing like 'bit field array'.

If we just spread the array, it will be difficult to accessed by index or in other form.

// Struct: RovExdataLeakageData [6] {1 fields}
struct RovExdataLeakageData {
    // [0, 6) NormalField: bool<48> leakage[6]
    bool leakage_1 : 1;
    bool leakage_2 : 1;
    bool leakage_3 : 1;
    ...
    bool leakage_48 : 1;
};

@xaxys
Copy link
Owner Author

xaxys commented Dec 2, 2023

Or maybe we should combine all these forms

struct RovlinkFrame {
    ...
    uint8<6> payload;
    ...
}

struct RovExdataLeakageDataUint8Array[6] {
    uint8<6> leakage [order="big"];
}

struct RovExdataLeakageDataBoolArray[6] {
    bool<48> leakage [order="big"];
}

struct RovExdataLeakageDataBoolArrayUnfolded[6] {
    bool<48> leakage [order="big", unfold = true];
}

struct RovExdataLeakageDataUint64[6] {
    uint64 leakage[6];
}

User should take payload field in RovlinkFrame as void * then select one RovExdataLeakageDataXXX struct to do second decode.

  • Use RovExdataLeakageDataUint8Array or just use payload to manipulate data in byte array.
  • Use RovExdataLeakageDataBoolArray in device with sufficient memory.
  • Use RovExdataLeakageDataBoolArrayUnfolded to manipulate data bit by bit.
  • Use RovExdataLeakageDataUint64 to manipulate data in a whole. (such as use leakage > 0 to determine if leakage happened)

However, in this form, user still can not do random access by index, unless they use normal bool array. Or maybe we should provide a macro to assistant this?

@xaxys xaxys moved this from In Progress to Todo in bubbler Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

1 participant