[Other] An Overview of Arrays and Memory
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.
最新文章
- Kafka 解析
- poj 1286&;&;poj2409 Polya计数 颜色匹配
- 原生DOM探究 -- NodeList v.s. HTMLCollection
- Scrum会议3(Beta版本)
- Cheatsheet: 2015 01.01~ 01.31
- UVA 11396 Claw Decomposition(二分图)
- 调试环境部署续:vs远程调试
- @synthesize 与@dynamic区别
- 常见的DBCP连接池配置
- 【Teradata SQL】字符串分割函数STRTOK和STRTOK_SPLIT_TO_TABLE
- Pinterest凭什么拥有那么多用户:机器学习是答案
- struts2 default.xml详解
- css:常见布局问题
- kubernetes微服务部署
- NET设计模式 第二部分 结构性模式(12):享元模式(Flyweight Pattern)
- 总结一些笔记上的C和C++知识点
- Linux C socket 封装
- 获取URL网页信息
- extjs中组件监听器里面的回调函数说明
- docker启动时报错
热门文章
- Codeforces Round #357 (Div. 2) A
- spring in action学习笔记十五:配置DispatcherServlet和ContextLoaderListener的几种方式。
- saltstack 实现haproxy+keepalived
- 洛谷P3112 [USACO14DEC]后卫马克Guard Mark
- Spinner用法与ListView用法
- VC版本与VS版本 对照表
- Python-mysql索引
- Laravel中setAttribute和queryScope的用法
- 转载——为Xamarin更好的开发而改写的库
- HDU 6112.今夕何夕-蔡勒公式 (2017";百度之星";程序设计大赛 - 初赛(A)1005)