Limit the number of local variables used in the internal loop of the function to a maximum of 12. In this way, the compiler can allocate these variables to arm registers; the compiler tries to assign a register to each local variable in the C function. If several local variables are not used repeatedly, the compiler will allocate the same register to them. When there are more local variables than available registers, the compiler will store excess variables in the stack. Because these variables are written into the memory, they are called overflow or replace (swapped out) variables, just as the contents of the virtual memory are replaced with the hard disk. Access to overflow variables is much slower than that of variables allocated in registers.
Solve the problem of multiple variables: organize multiple related parameters into a struct and pass a struct pointer to replace multiple parameters.
Typedef struct {
Char * q_start,
Char * q_end,
Char * q_ptr,
} Queue;
Void queue_bytes (queue * queue, char * data, unsigned int N)
{
Char * q_ptr = queue-> q_ptr;
Char * q_end = queue-> q_end;
Do
{
* (Q_ptr ++) = * (Data ++ );
If (q_ptr = q_end)
{
Q_ptr = queue-> q_start;
}
} While (-- N );
Queue-> q_ptr = q_ptr;
}