Best Data Structure for complex struct

I'm building a system that requires to storage of some values calculated by some rather complex algorithms.

I currently have 2 structs set up for them as so:

struct Day
{
    uint8_t ValueA;
    uint8_t ValueB;
    uint8_t ValueC;
    uint8_t ValueD;
    uint8_t ValueE;
    uint32_t TimeA;
    uint32_t TimeB;
};

struct Month
{
    uint8_t Month;
    uint8_t Year;
    uint8_t DaysInMonth;
    uint8_t ValueA;
    Struct1 Days[31];
};

I need an array that stores 2 of these Month Structs. One for current month and one for next month. So this is declared as follows:

Month Months[2];

I guess my question is 2 fold. Is there a better way to store/structure this data?

Is there a way to easily copy the values from Months[1] to Months[0]?

Try
Months[0]=Months[1];

Better for what? Use less memory, work faster, anything else?

see memcpy()

Nothing to do with your question, but these may be more useful as an array of values as opposed to separately named. Maybe same with the time unsigned longs.

struct Day
{
    uint8_t aeValues[5];

    uint32_t abTimes[2];
};

a7

That should be:
Day Days[31];

1 Like
Day days[31];

Would probably be better so the object doesn't have the same name as the datatype.

1 Like

Wow! Thank you.

I never tried this as I knew you could do this with arrays so didn't even think to try it. So question... if you try and do this with a normal array it fails so why does it work with an array structed like this? Slightly confused.

do you mean something like

int array1 [] = { 1, 2,3, 4 };
int array2 [] = { 5, 6, 7, 8 };
...
     array2 = array1;

why is a copy of data necessary from one index to another at all?
Your structure has a time stamp any way. Wouldn't the usage of the array like a ring buffer be more appropriate?

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.