《(7.1)--7.1Basicprincipleofdatastorage.pdf》由会员分享,可在线阅读,更多相关《(7.1)--7.1Basicprincipleofdatastorage.pdf(9页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、Basic Principle of Data StorageBasic Principle of Data Storage7.1When using a computer to solve an actualproblem,some space which is needed to storethe data to be processed,the intermediate resultand the final result of the operations,is thememory space of the computer.The memory space contains a la
2、rge number ofstorage units.Each storage unit is identified by aunique memory address and can store 1 bytedata.The number of the memory address startsfrom 0 and increases by 1 in sequence.Thefigure on the right is an example of memoryaddress.Basic Principle of Data Storage7.1 In a 32-bit system,the m
3、emory address consists of 32-bit binary numbers.The memory address number starts from 0 and the maximum is 232-1.Therefore,the maximum memory capacity supported by the 32-bit system is 232(=4G)bytes in theory.In a 64-bit system,the memory address consists of 64-bit binary numbers.Therefore,the maxim
4、um memory capacity supported by the 64-bit system is 264(=16777216T)bytes in theory.Basic Principle of Data Storage7.1When running a program,the system will allocate some memory space to the program.According to the different types of data stored in the memory space,it can be divided into 4 areas:Co
5、de areastores the code of the program(when the program is run,the program will be loaded into the code area of memory before execution).Global data areastores global data and static data in the program(when defining global variables or static variables,memory space will be allocated in the global da
6、ta area to store data).Basic Principle of Data Storage7.1Heap areastores the dynamic data in the program(when using the dynamic method to allocate memory,memory space will be allocated in the heap area to store data.We will learn about dynamic memory allocation later).Stack areastores local data in
7、the program(when defining local variables,memory space will be allocated to store data in the stack area).Basic Principle of Data Storage7.1When defining any variable,the system will allocate a certain size of memory space for it.Accessing the variable is actually accessing the data in its correspon
8、ding memory space.Basic Principle of Data Storage7.1 The memory address in a 32-bit system consists of 32-bit binary numbers.Hexadecimal number is the compressed representation of binary number.1 digit of a hexadecimal number is equivalent to 4 bits of a binary number.To simplify address representat
9、ion,memory addresses in 32-bit systems are usually represented by 8 hexadecimal digits.Similarly,memory addresses in 64-bit systems are usually represented in 16 hexadecimal digits.Basic Principle of Data Storage7.1ExampleIn C+,given a variable definition statement:int a=0 x61626364;the system will
10、allocate a 4-byte memory space for the variable a,and the data stored in this piece of memory space is 0 x61626364.Assume that the first address of the variable memory space is 0 x0025f758,then:0 x640 x630 x620 x610 x0025f7580 x0025f7590 x0025f75a0 x0025f75bMemory AddressDataBasic Principle of Data
11、Storage7.1Tip:In fact,when defining a variable,the memory space allocated by the system for the variable may be different in different environments.Therefore,when you define the variable a on your own computer,you may check that the corresponding memory space is generally inconsistent with the memory address shown in the right figure.sint a=0 x61626364;couthexaendl;cout&aendl;