Packing and unpacking

Mainly related to performance loss

Boxing is to turn the value type in the stack into an instance of object and put it in the heap. Then store the address of the instance in the stack.

Unboxing is to move the data of the instance in the heap into a value type and put it in the stack

int x=100;//The following is the memory situation, It is placed in the stack

share picture

object obj;//

share picture

obj=x;//This sentence first open up an address in Heap, put 100 in the stack, and then put the address 000000113 The original obj references the memory of the parameter, and the boxing is complete.

share picture

int y=(int)obj;//Unboxing, the value in the heap is moved to the stack as required, that is, int

Share Picture

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2680 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.