Skip to content

Latest commit

 

History

History
47 lines (35 loc) · 806 Bytes

Week1-1.md

File metadata and controls

47 lines (35 loc) · 806 Bytes

Array/数组

09/10/2021 KevinZonda

Construct

final int[] nums = new int[4];

in OS++

final nums = allocate_memory(4*1);

Operate

x = nums[3];
numds[3] = 4;

OS++

x = Mem[nums + 3];
Mem[nums + 3] = 4;

Memory Management/内存管理

  • Java
    • memory allocation is automatic
    • freeing memory is automatic (by the garbage collector)
    • bounds of arrays are checked
  • In C or C++
    • allocations is explicit (similar to OS++ and Mem[-])
    • freeing memory is explicit (similar to OS++ and Mem[-])
    • bounds are not checked

Java is slower and safe, C (or C++) is fast and dangerous.