Stack direction and size end storage

Source: Internet
Author: User

In the design of the program, will involve the use of the stack, in fact, stack refers to the heap and stack, they are two different concepts, where the heap is through the user to call the memory space, users need to actively allocate and release, if only allocated and not even if released, then there may be a memory leak problem, the results of incalculable The stack is the memory space that the system automatically calls, and the system will automatically release the space according to the actual situation.

In peacetime usage, we need to pay attention to the growth direction of the stack (here only refers to the stack), in general, when the stack pointer (stack top) from high address to low address growth, we call the downward growth, when the stack pointer (stack top) from the low address to high address growth, we call upward growth.

In the program design we also need to pay attention to the way data is stored---big-endian storage/small-end storage.

Big-endian storage---High-bit bytes of data are kept in low-memory addresses, while the low-level bytes of data are kept in the higher address of memory------(I am wayward)

Small-end Storage---High-level bytes of data are stored in the memory of the higher address, and the low byte of data is kept in the memory of the lower address

Size End test Method:

1.

// return 0:big_endian // return 1:little_endian  Char Checkendian (void) {  int1;   If(* (char *) & number)     return1;  Else    return0;}  

2.

/**/**/int  Checkendian    () {int  Char b;} C;     1 ;     return 1 );}

3.

 // return 0:big_endian  // return 1:little_endian  int  Checkendian (void   int  a = 0x12345678   char  *p= (unsigned char  *    ) &A;  if  (0x78  ==* p)  return  1      else   Return0;}  

Stack direction and size end storage

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.