C Language Learning Diary 8

Source: Internet
Author: User

Why do I need memory to run the 4.1.1 program?

4.1.1.1 The purpose of running a computer program.

4.1.1.2 computer program running process

4.1.1.3 von Neumann structure and Harvard structure

The von Neumann structure is: Data and code are put together.

The Harvard structure is: data and code exist separately.

What is code: function

What is data: Global variables, local variables.

4.1.1.4 dynamic memory dram and static memory SRAM.

4.1.1.5 Summary: Why do I need memory?

4.1.1.6 How to manage memory

From the operating system point of view: The operating system master all the memory, because the memory is very large, so the operating system divides the memory into 1 pages (typically 4KB), and then the page to manage. The page is managed in a more granular way, in bytes. The operating system provides us with some interfaces for memory management, and we only need to use the API to manage memory. For example, use malloc in the C language to request free release.

When there is no operating system: In the absence of an operating system (bare-metal program), the program needs to directly manipulate memory.

From a linguistic point of view: Different languages provide different interfaces for operating memory. For example, the assembly: no memory management, direct use of memory address, C language compiler to help us to manage the direct memory address, we all through the compiler provided by the variable name and so on to access memory; C + + language for memory use further encapsulation, we can use new to create objects (in fact, to allocate memory for objects), Then use Delete to remove the object (in fact, to free memory). If the programmer new an object, but the use of forgotten delete will cause this object to occupy the memory is not released, this is a memory leak. Java/c#: These languages do not directly manipulate memory, but instead use virtual machines to manipulate memory. So the virtual machine as our Programmer's agent, to help us deal with the release of memory work. Virtual opportunities to help us manage. But in fact, he this virtual machine to reclaim memory is a cost to pay. When our program is very concerned about performance (such as the operating system kernel) will be used C + +, when we are very concerned about the speed of the development program, we will use java/c# and other languages.

4.1.2.1 What is memory (hardware and logical angle)

On the hardware: is an accessory.

From a logical point of view: it can be accessed randomly (meaning that the memory address can be accessed as long as it is given an address) and can be read and written. Memory is naturally used to store variables in programming (because there is memory, so C can define variables, and a variable in C will actually correspond to a unit in memory).

Logical abstraction of 4.1.2.2 memory

4.1.3 Bits and bytes

4.1.3.4 Words and half words

4.1.3.4 Memory bit width

Hardware: The implementation of hardware memory itself is a width.

Logically, the memory bit width is logically arbitrary, logically speaking, regardless of the size of the memory bit, it does not affect my operation. But our operation is not pure logic but need hardware to execute, so we can not do anything, so many of our actual operations are limited by the characteristics of the hardware.

C Language Learning Diary 8

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.