当前位置:网站首页>Why does the subscript of the array start from 0 instead of 1?
Why does the subscript of the array start from 0 instead of 1?
2022-04-23 06:07:00 【New ape and horse】
Catalog
Two Array model representation
3、 ... and Array addressing calculation
One Array addressing formula
a[i]_address = base_address + i * data_type_size
data_type_size Is the size of each element in the array .
Two Array model representation
With int[] a = new int[10] For example . Computers give arrays a[10], Allocated a contiguous memory space 2000~2039, The first address of the memory block is base_address = 2000.
3、 ... and Array addressing calculation
Suppose the array is from 0 Start , Computation first 9 The first element formula is :a[9]_address = 2000 + 9 * 4 = 2036;
Suppose the array is from 1 Start , Computation first 9 The first element formula is :a[9]_address = 2000 + (10-1) * 4 = 2036
contrast : Array from 1 At first, it is equivalent to one more subtraction operation for each random access to array elements , about CPU Come on , Just one more subtraction instruction . Arrays are very basic data structures , Random access to array elements through subscripts is a very basic programming operation , The optimization of efficiency should be as extreme as possible .
Conclusion : In order to reduce one subtraction operation , Array selected from 0 Numbered starting , Not from 1 Start .
版权声明
本文为[New ape and horse]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220533487760.html
边栏推荐
- Understand the current commonly used encryption technology system (symmetric, asymmetric, information abstract, digital signature, digital certificate, public key system)
- MySQL basic madness theory
- Remedy after postfix becomes a spam transit station
- Multithreading and high concurrency (2) -- detailed explanation of synchronized usage
- PyTorch笔记——实现线性回归完整代码&手动或自动计算梯度代码对比
- What is the difference between the basic feasible solution and the basic feasible solution in linear programming?
- EditorConfig
- 治疗TensorFlow后遗症——简单例子记录torch.utils.data.dataset.Dataset重写时的图片维度问题
- Practical operation - Nacos installation and configuration
- Anaconda
猜你喜欢
线性代数第二章-矩阵及其运算
Development environment EAS login license modification
String notes
Pyemd installation and simple use
Multithreading and high concurrency (1) -- basic knowledge of threads (implementation, common methods, state)
你不能访问此共享文件夹,因为你组织的安全策略阻止未经身份验证的来宾访问
Denoising paper - [noise2void, cvpr19] noise2void learning denoising from single noise images
Font shape `OMX/cmex/m/n‘ in size <10.53937> not available (Font) size <10.95> substituted.
Pytorch learning record (V): back propagation + gradient based optimizer (SGD, adagrad, rmsporp, Adam)
Understand the current commonly used encryption technology system (symmetric, asymmetric, information abstract, digital signature, digital certificate, public key system)
随机推荐
Pyqy5 learning (4): qabstractbutton + qradiobutton + qcheckbox
rsync实现文件服务器备份
filebrowser实现私有网盘
Dva中在effects中获取state的值
PyTorch笔记——通过搭建ResNet熟悉网络搭建方式(完整代码)
Anaconda安装PyQt5 和 pyqt5-tools后没有出现designer.exe的问题解决
RedHat6之smb服务访问速度慢解决办法记录
Development environment EAS login license modification
Chapter 4 of line generation - linear correlation of vector systems
Pytorch学习记录(十):数据预处理+Batch Normalization批处理(BN)
Pytorch introduction notes - use a simple example to observe the output size of each layer of forward propagation
Common programming records - parser = argparse ArgumentParser()
Protected (members modified by protected are visible to this package and its subclasses)
Automatic control (Han min version)
Paper on Image Restoration - [red net, nips16] image restoration using very deep revolutionary encoder decoder networks wi
Comparative study paper - [Moco, cvpr2020] momentum contract for unsupervised visual representation learning
Pytorch学习记录(十一):数据增强、torchvision.transforms各函数讲解
Kingdee EAS "general ledger" system calls "de posting" button
The official website of UMI yarn create @ umijs / UMI app reports an error: the syntax of file name, directory name or volume label is incorrect
Pytorch learning record (III): structure of neural network + using sequential and module to define the model