Multi-use structure element - pointers or unions?
Posted: Tue Sep 30, 2025 2:06 am
Im creating multiple lists that reference particular entries by ID. In other words, each list entry will have an initial index of so many bytes that is called by other lists, to help separate the data but keep it linked. Imagine multiple lists whose first number in each line is the same, indicating that the data is linked.
So the structure of each line of the list uses a quad for its ID, but I am calling this variable in every list structure. This means that the memory for these lists will be filled with a repetition of these quads found in different lists.
I think I can use pointers to reserve memory instead if quad variables, but I'm hesitant about using them because I don't know how to use them in actual code. They're a little bit above my head and hard to understand why they're even necessary. As opposed to just using a variable.
However, I just saw in the manual something called a structure union, and even though it's a little bit complicated I wondered if I could use that to call for the same variable in each list, since they're all accessing the same exact value.
I see very little info on structure unions, so could someone help me to understand when theyre helpful, and the strategy for using them? Would they helpful in my situation, trying to save memory by referring to the same variable?
So the structure of each line of the list uses a quad for its ID, but I am calling this variable in every list structure. This means that the memory for these lists will be filled with a repetition of these quads found in different lists.
I think I can use pointers to reserve memory instead if quad variables, but I'm hesitant about using them because I don't know how to use them in actual code. They're a little bit above my head and hard to understand why they're even necessary. As opposed to just using a variable.
However, I just saw in the manual something called a structure union, and even though it's a little bit complicated I wondered if I could use that to call for the same variable in each list, since they're all accessing the same exact value.
I see very little info on structure unions, so could someone help me to understand when theyre helpful, and the strategy for using them? Would they helpful in my situation, trying to save memory by referring to the same variable?