2021-1-17

Today I mainly learned memory functions and structure
1, memcpy: void memcpy(void dest,const void src,size_t num); copy num bytes of the memory content of src to the memory of dest, and cannot be an overlapping copy . Will not stop when encountering \0.
2. memmove: memmove(): overlapping copy, the parameters and return type are the same as above, it is to copy the overlapping data. The unit of copy is byte.
3. memcmp: memcmp(const void
dest, const void src, size_t num): compare the contents pointed to by dest and src and compare num bytes one to one.
4. Memset: memset (void
dest, int c, int count) memory setting, change the count bytes of the data pointed to by dest to c.
The memory function mainly needs to pay attention to one point, the size of its operations are all bytes.
Structure
definition and initialization
struct stu
{
char c;
int a;
char arr[];
struct S s;
}; This is the definition
struct stu s={'a',10,"hello world",{}}; this is initialization.
The structure size calculation method
must first understand the structure memory alignment
rules
1. The first member is stored at the address with offset 0.
2. The other members are stored at addresses that are integer multiples of the alignment.
The alignment number calculation
is the smaller of the compiler default value and the member data size.
3. The size of the structure is an integer multiple of the maximum alignment of its members.
4. If the structure is nested with other structures, the nested structure is aligned to an integer multiple of the maximum alignment number of its internal members, and the overall size of the structure is an integer multiple of the overall alignment number.
#pragma pack(4); Set the default alignment number to 4.
#pragma pack(); Cancel the set default alignment number.
offsetof (structure name, member name) seeks member offset.
The structure should pass the address as much as possible.

Guess you like

Origin blog.51cto.com/15085121/2594493