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.

最新文章

  1. Kafka 解析
  2. poj 1286&&poj2409 Polya计数 颜色匹配
  3. 原生DOM探究 -- NodeList v.s. HTMLCollection
  4. Scrum会议3(Beta版本)
  5. Cheatsheet: 2015 01.01~ 01.31
  6. UVA 11396 Claw Decomposition(二分图)
  7. 调试环境部署续:vs远程调试
  8. @synthesize 与@dynamic区别
  9. 常见的DBCP连接池配置
  10. 【Teradata SQL】字符串分割函数STRTOK和STRTOK_SPLIT_TO_TABLE
  11. Pinterest凭什么拥有那么多用户:机器学习是答案
  12. struts2 default.xml详解
  13. css:常见布局问题
  14. kubernetes微服务部署
  15. NET设计模式 第二部分 结构性模式(12):享元模式(Flyweight Pattern)
  16. 总结一些笔记上的C和C++知识点
  17. Linux C socket 封装
  18. 获取URL网页信息
  19. extjs中组件监听器里面的回调函数说明
  20. docker启动时报错

热门文章

  1. Codeforces Round #357 (Div. 2) A
  2. spring in action学习笔记十五:配置DispatcherServlet和ContextLoaderListener的几种方式。
  3. saltstack 实现haproxy+keepalived
  4. 洛谷P3112 [USACO14DEC]后卫马克Guard Mark
  5. Spinner用法与ListView用法
  6. VC版本与VS版本 对照表
  7. Python-mysql索引
  8. Laravel中setAttribute和queryScope的用法
  9. 转载——为Xamarin更好的开发而改写的库
  10. HDU 6112.今夕何夕-蔡勒公式 (2017"百度之星"程序设计大赛 - 初赛(A)1005)