A3. Limit the number of local variables used by the function cyclically. A maximum of 12 local variables can be entered.

Source: Internet
Author: User

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;

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.