|Byte | Nothing | Int | => As is today, loss memory.
| B | N | I | I |
8bits 8bits 8bits 8bits
|Byte | Int | Free | => As should be, gain memory.
| B | I | I | F |
8bits 8bits 8bits 8bits
Hi, I’m using dsPIC33F 16 bits with MPLab, I’m with problem with loss of memory, I’m mounting structs containing bytes and ints, but when I use sizeof(), the value returned not is the expected, the value is always higher. Has some setup to do on MPLab or have no way? In both examples, I have one byte and one int, but in the first I loss one byte of memory, adding one byte on the final result, and always I make this exact structure, it adds one byte after int.
I think their compilers are GCC based so you can use __attribute__((packed)) on individual structure variables or -fpack-struct compiler switch to pack all structures.
One comment, on the dsPic Processor, like many processors today, multi-byte numbers may not be placed at arbitrary memory locations, but must be aligned to some power of 2 for addresses. 16 bit numbers on the dsPic must be stored on even addresses or the processor will not fetch them correctly. If you try to access a 16 bit word at an odd address, the processor will raise an address error execption.
One comment, on the dsPic Processor, like many processors today, multi-byte numbers may not be placed at arbitrary memory locations, but must be aligned to some power of 2 for addresses. 16 bit numbers on the dsPic must be stored on even addresses or the processor will not fetch them correctly. If you try to access a 16 bit word at an odd address, the processor will raise an address error execption.
So the order in which you list the members inside the structure will also make a difference. Dont have a char followed by an int followed by a char, but instead a char followed by a char followed by an int.
Int followed by char followed by another char won’t lose space. A structure of an int followed by a char, and that is all, will still take 4 bytes as is required to make array work.