2 QQ 33892372 Qq_338923722016.01.30 17:48 questions

On the C language, the use of malloc..

C dynamic malloc language acquisition in the largest space and what about computer?
C dynamic malloc language acquisition in the largest space and what about computer?

The 6 answer

Caozhy   Ds   Rxr 2016.01.31 07:58
Has adopted

First of all, the computer's physical memory, computer, computer addressable address space, malloc application, operating system process address space concepts are different.

Computer addressing capability is decided by the word length, a 32-bit computer, addressing capability is 4GB. Note that these addresses and DMA BIOS IO, reserved address, it was left to the address space of the memory is about 3.5GB about specific computer different)
The maximum memory addressing capability of computer determines the physical access to the computer. But the physical memory may be larger than it, may also be smaller than. You buy a computer, will know the memory size, 2GB 4GB 8GB and so on.
The computer division of the virtual address space for each process independently. For windows (32bit), 2GB space users, 2GB system is more space. This determines a 32bit process that can access the 2GB memory is not just 2GB? No, because the stack, static area and so on also takes up some address, and the address on the stack is not continuous, if a lot of debris, there will be no spatial distribution.
If your computer is installed only 1GB of memory, is not the only access to the 1GB (or less)? No, because the operating system will use the page file (commonly known as virtual memory, virtual memory is the virtual address space, but to get the disk as the page swap space simulated memory).
Then malloc is assigned a lot of space, is not necessarily memory overflow / memory error? No, because the operating system memory allocation is in accordance with the principle of lazy allocation. That is if you don't have access to the actual memory, so the light distribution, the virtual memory address is assigned out, but did not use the actual memory, there is no allocation page. So malloc can allocate memory than actually use more physical memory.

Lm_whales   Rxr 2016.01.31 16:02

Modern operating system, users are available memory, virtual memory, and not the physical memory size
But how much memory, and the computer can open the number of processes, efficiency and large amount of data process, the relationship is still not small
Physical memory is small, the page will often exchange, a large amount of data the program (and if there are a lot of process to run), prone to memory jitter.
Virtual memory, the main problem is CPU and operating system,
To provide you with free space much address some space. Nor can be used for applications
Operating system, the hardware must take a part of memory space. The other is the available memory space.
The available memory space, static space, planing to application code space, stack space
And the other must occupy memory space. It can be dynamically allocated heap space.
32Bits Windows is hard to use memory above 2G,
By means of some of the highest available 3G memory, but not necessarily the actual physical memory.
Of course, if you have 4G of ram.
The probability of the physical memory program is still quite large
64Bits should be no 4G memory limit

Lm_whales Malloc is C, the C++ library function, and the operating system is, most API calls to achieve it
About a month ago reply
Qw2384008   2016.01.31 16:20

Version 2.

Subroutine CALL_ pickup.
Integer type. The parameter object address.
Article. Parameters of address, integer, and address segment
The local variable items. EBP, integer
The local variable EBP. Pick up, integer

EBP = sixteen to ten items (3 # items)
Pick ten (EBP = sixteen to 3 # pickup CALL)
In the code ({96, 139, 181, 8, 0, 0, 0, 139, 54, 139, 141, 252, 255, 255, 255, 139, 12, 49, 255, 181, 12, 0, 0, 0, 139, 133, 248, 255, 255, 255. 255, 208, 97})

Fk002008   2016.01.31 01:33

C dynamic malloc language acquisition in the largest space and what about computer?

Sure and the computer's memory and CPU.

A limited memory storage space on the boundary theory
CPU can handle the word processing is, the bigger the word size, the greater the volume of the instruction itself, memory is also large

The other is your C program when running, it is assigned to a process space.
The process of space resources limited good.
You use malloc to allocate memory space should not escape the process of memory space.

If the more you distribution, it should be more resource occupation process.

So the operating system and the type and relationship, what can give the process of how much space.

Cnzjp9   2016.01.31 15:09

The size of the largest malloc application space and operating system on the process of setting the heap space, Never mind and physical memory.

91program   Ds   Rxr 2016.01.30 21:17

Of course, at least to provide computer memory available for memory size greater than malloc.

Csdn user default icon
Upload photo
Insert a picture