One integer takes 32bit in memory, 1 byte = 8bits, therefore one integer takes 4 bytes.

Now let's assume we have an array: [1,2,3]

4bytes .   4bytes .  4bytes

| . | . | . | . | . | . | . | . | . | . | . | . |

1 .            2 .          3

It tooks 4 * 3 bytes for three integers in an array. What if we want to add two more integers into the array, how the memory allocate?

A. it appends another 8 bytes in the end

B. it recreate an new array with 4 * 5 bytes size.

B. is the correct answer. It always create a new larger array and delete the old array. The simple reason for this is because we never know after array, it might have other code:

var a = [1,2,3]
var c = 4

4bytes .   4bytes .  4bytes     4bytes

| . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . |

1 .            2 .          3 .        c=4

It assign 4 bytes to variable c in memory. We cannot simply append more memory after the old array.

[Other] An Overview of Arrays and Memory的更多相关文章

  1. MAT(memory anlayzer tool)使用方法

    Analyzing and understanding the memory use of an application is challenging. A subtle logic error ca ...

  2. C# to IL 12 Arrays(数组)

    An array is a contiguous block of memory that stores values of the same type. These valuesare an ind ...

  3. Nandflash 驱动移植

    前段时间,研究了一下4G的Nandflash驱动.手头上只有飞凌6410BSP自带的Nandflash驱动,该驱动不支持K9GAG08U0D(2G)和K9LBG08U0D(4G)的Nandflash. ...

  4. C语言 cgi(3)

    1cs3157 – Advanced ProgrammingSummer 2014, Project 1, 150 pointsJune 17, 2014Follow these step-by-st ...

  5. C语言程序代写(qq:928900200)

    1cs3157 – Advanced ProgrammingSummer 2014, Project 1, 150 pointsJune 17, 2014Follow these step-by-st ...

  6. Best jQuery Plugins of the Month – May 2014

    1. jQuery referenceSection jQuery referenceSection by Scott Mascio ensures to help users in adding a ...

  7. Java 伙伴系统(模拟)

    参考:https://labrick.cc/2015/10/12/buddy-system-algorithm/ 代码过烂 不宜参考. output: [operating.entity.Heap@4 ...

  8. PostgreSQL源码安装文档

    This document describes the installation of PostgreSQL using the source    code distribution. (If yo ...

  9. Cache replacement policies 缓存实现算法

    Cache replacement policies - Wikipedia https://en.wikipedia.org/wiki/Cache_replacement_policies Cach ...

随机推荐

  1. js函数调用与声明 (for时注意)

    可以的: test();  // 直接function 方式声明的函数可以直接调用,后声明 function test(){} aa();   //error  var 方式声明的函数需先声明后调用v ...

  2. 使用srvany.exe把程序安装成windows服务

    srvany.exe介绍 srvany.exe是Microsoft Windows Resource Kits工具集的一个实用的小工具,用于将任何EXE程序作为Windows服务运行.也就是说srva ...

  3. 基于UDT connect连接通信以及文件传输--服务端

    网上与UDT相关的资料不多,与UDT相关的源码例子更少.最近在接触UDT,也是因为缺少相关的资料,导致学习起来甚感痛苦.下面将我自己这两天弄出来的代码贴出来,希望对在寻找相关资料的童鞋有一定的帮助.与 ...

  4. DropZone图片上传控件的使用

    前台代码: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w ...

  5. This template requires a more recent version of the Android Eclipse plugin. Please update from versi

    新建android project的时候遇到这个错误: 解决方法:①直接修改F:\JAVA\SDK\android-sdk\tools\templates\activities (对应你的JAVA S ...

  6. -webkit-box-flex: 1;属性和 float 属性冲突造成元素看不见的BUG

    今天切图的时候发现了这个问题,样式是这样的: .check-btns-box .check-btn{float: left;-webkit-box-flex: 1;-moz-box-flex: 1;- ...

  7. 用了GradientDrawable后,当点击控件时,控件大小发生变化

    android新手:发现一个很奇怪的问题,用了GradientDrawable后,当点击控件时,程序自动使我的一些控件大小保持一致,为什么呢,我就是不想它们保持一致啊 改了好久好久:GradientD ...

  8. Python Unittest与数据驱动

    python中有一个装饰器类DDT,通过它我们可以复用代码,达到数据驱动测试的目的,该类的官方介绍可以参考 http://ddt.readthedocs.io/en/latest/index.html ...

  9. Python的并发并行[3] -> 进程[0] -> subprocess 模块

    subprocess 模块 0 模块描述 / Module Description From subprocess module: """Subprocesses wit ...

  10. 10.28 HTML DOM