"8.0" questions about dynamic arrays of Java and C

Source: Internet
Author: User

1.java:

Java itself is not able to implement dynamic arrays, this Java itself does not directly manipulate the pointer is related to "although I think in theory should be the same as C, can be done, but Java does not provide, specific reasons, such as know to add." So the collection of Java, such as the ArrayList collection, is how to implement a "dynamic array". The principle is: the bottom of the ArrayList is an array a "object[] a = new object[]", if you need to change the size of the ArrayList, then discard the original reference to a, and then a new array [ArrayList] B = New object[], length custom], and reference it.

2.c language:

Principle:

(1) Dynamic array-Create, use malloc function: The role of malloc is to dynamically allocate a custom length of contiguous space in memory;

(2) Dynamic array--changing the size of the array, using the Relloc function: The Relloc effect is:

A) Reduce the length of the array: when the memory itself has the remaining space, you can take off its own tail memory as needed "description: The operation of the memory is limited to the memory block allocated by the array";

b) Increase the length of the array: when there is extra space at the end of the memory where the array is located, add the memory directly to the back of the original memory block, and if the original memory is out of space, Relloc re-allocates a new memory space and copies the contents of the original memory to the new memory block.

"8.0" questions about dynamic arrays of Java and C

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.