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. async-http

    android-async-http开源框架可以是我们轻松的获取网络数据或者向服务器发送数据,使用起来也很简单,下面做简单介绍,具体详细使用看官网:https://github.com/loopj/a ...

  2. js执行时间(调试)

    js 执行时间 function use_time(func) {    var start = new Date().getTime(); console.log(start);        fu ...

  3. "贪心"的考试

    先来落实比较简单的T3,T4 T3  团结的队伍 team 题目描述 众所周知,长郡信息组是一个团结友爱的优秀团队.为了弘扬团队精神,践行社会主义核心价值观,秉承朴实沉毅的校训,信息组决定外出游玩(. ...

  4. python 使用urllib2下载文件

    #! usr/bin/python #coding=utf-8 import urllib2 fp = open('test', 'wb') req = urllib2.urlopen('http:/ ...

  5. 多线程调用COM组件的体会(CoInitialize)(转)

    原文转自 https://www.cnblogs.com/manors/archive/2010/05/17/COM_Initialize_STA_MTA.html 与设备打交道时,我们经常用到COM ...

  6. mysql 共享空间转为独立表空间

    由于以前的mysql配置为共享表空间,服务器空间不足,清理日志表里的数据后,数据库并没缩小,照成空间浪费,现在修改为独立表空间 #独立表空间innodb_file_per_table=1 #停止事物日 ...

  7. css之其它技巧和经验列表

    其它技巧和经验列表(*以下实例默认运行环境都为Standard mode): 如何让层在falsh上显示? 方法: ``` 设置flash的wmode值为transparent或opaque ``` ...

  8. Android_html5交互 弹框localstorage 存值 整体案例

    经历2周多的时间 终于是完成了还算可以的android 整体案例了,分享下给大家  也希望自己有时间回过头来看看当初研究android的纠结心情.痛苦的经历是开发android 大部分都是在网上找解决 ...

  9. ASP.NET Code First Update-Database

    问题描述: 复制了一个模块化的MVC5的项目,模块化的解释是说不同功能的模块分开来放的. 明确每个模块都是做什么工作的. 首先最基本的,就是根据Apps.Models模块来创建数据库了. 做法是卸载A ...

  10. HDU 6301.Distinct Values-贪心、构造字典序最小的数列 (2018 Multi-University Training Contest 1 1004)

    HDU6301.Distinct Values 这个题就是给你区间要求区间内的数都不相同,然后要求是字典序最小,直接贪心走一遍,但是自己写的时候,思路没有错,初始化写挫了... 将区间按左端点小的排序 ...