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. idea创建maven项目需要注意的问题

    idea创建maven项目之后,我从deployment中看到报部署错误的问题,下图是解决问题的办法如下图所示:

  2. Python设置函数调用超时

    http://blog.sina.com.cn/s/blog_63041bb80102uy5o.html 背景:        最近写的Python代码不知为何,总是执行到一半卡住不动,为了使程序能够 ...

  3. bzoj3638 Cf172 k-Maximum Subsequence Sum

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3638 [题解] 看到k<=20就感觉很py了啊 我们用一棵线段树维护选段的过程,能选到 ...

  4. 更改mvc版本的时候,手动修改交3.0改到4.0,将razor改到2.0,仍然提示出现错误,mvc3.0

    偶然碰到,更改mvc版本,由3.0升级到4.0,但是依然提示3.0的错误 几经周折排查,最终发现 <runtime> <assemblyBinding xmlns="urn ...

  5. JS与jQuery中html-与-text方法的区别

    所有的实例均用下面的html <div id="id0"> <div id="id1"> 直接text <p> <sp ...

  6. JS操作checkBox

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

  7. [9018_1963][IOI_1998]Picture

    题目描述 N(N<5000) 张矩形的海报,照片和其他同样形状的图片贴在墙上.它们的边都是垂直的或水平的.每个矩形可以部分或者全部覆盖其他矩形.所有的矩形组成的集合的轮廓称为周长.写一个程序计算 ...

  8. Inline Hook

    @author: dlive IAT Hook时如果要钩取的API不在IAT中(LoadLibrary后调用),则无法使用该技术.而Inline Hook不存在这个限制. 0x01 Inline Ho ...

  9. usb驱动---What is the difference between /dev/ttyUSB and /dev/ttyACM【转】

    转自:http://blog.csdn.net/ppp2006/article/details/25654733 https://www.rfc1149.net/blog/2013/03/05/wha ...

  10. 如何让natTable表格支持自定义多个右键菜单

    在nebula中,官方默认提供了一个构造natTable的builder类,并且提供了一个debugInfo的默认右键菜单,但是当我们通过官方提供的builder去创建natTable,并且要添加多个 ...