Relationship between heapalloc, globalalloc, and virtualalloc

Source: Internet
Author: User

Virtualalloc allocates more than 1 page of Ram at a time. Each allocation is an integer multiple of the page.
You don't want to waste the remaining 4095 bytes in order to allocate one byte space. OK. You can write algorithms by yourself.
Match pages. Then, the pages will be divided every time a small amount of data is allocated. What? You are too stupid to write points
Configuration algorithm? Haoba Kernel32 provides you with a solution. Use heapalloc/globalalloc to allocate Ram. In this way,
Kernel32 helps you complete the allocation and minimize the number of idle and occupied areas used for tracking
Data structure.

A long time ago, there was a product called windows. At that time, windows was 16bit. The address space was quite tight.
Not rich enough. You still need to get a grain pass to get it. You have called globalalloc and paid for it in the same way.
Globalalloc is not enough. Sometimes you need glocallock to make sure you can get your stuff. Otherwise you
The pointer will be invalid. Your application will be killed. It will be too far away. Later, the OS has evolved. I think the grain can be canceled.
Pass the ticket. But you must use the new version of the bill. That is, heapalloc. As long as there is no problem with the number of RAM in the market
. Your heapalloc is okay. You can always get things. However, you can't say you have a 2000-version bill,
So the version 80 will expire immediately. Then globalalloc will have to continue circulating. When can it be circulated.
Nobody knows.

 

Globalalloc and localalloc are both memory allocation functions provided by Windows systems. Their differences are derived from the 16-bit code era. At that time, there were no different process memory.
Space. globalalloc is allocated on the global and public remote stacks, while localalloc is allocated on the near-heap of the task itself. On the Win32 platform, these two functions are identical.
Are allocated in the memory space of the process itself. After the lock, the result is a normal pointer (32-bit near pointer ).

 
The difference between new and them is not too big, because it is related to the constructor and exception mechanism of c ++. In general, the new in the compiler uses malloc to allocate memory. Use malloc and the other two
Functions should be more reasonable. In general, the implementation of malloc is not allocated from the system heap, but from the heap managed by the Runtime Library connected by the compiler, compiled by the development tool on the Win32 platform
In the results, heapcreate is usually used to create a heap, heapalloc and heaprealloc are used to maintain the heap space growth, and heapdestroy is used to delete the heapdestroy
Heap. When malloc is used for allocation and free release, the code of the Runtime Library allocates space from the heap and returns the space to the heap, and maintains the data structure in the heap.

 
Since the management of the malloc heap is managed by the Runtime Library itself, when we use the static Runtime Library, if malloc is used to allocate memory in one DLL and in another DLL
Free to release it, usually produces problems, because each DLL is connected to a running library code, and thus there is a local heap of its own, when free is used to release the memory, it assumes that the memory is used.
It is allocated in its own heap, leading to errors. The memory allocated through globalalloc and localalloc does not exist.

 

Heapcreate has completed the heap creation operation. Both heapalloc, heaprealloc, and heapfree are the memories allocated and released from the heap.
Number. That is to say, the Windows system has provided us with a complete set of operations to use our own local heap, but we do not see the method for specifying the allocation policy. Based on the source code provided by the compiler
Look, the main functions of the malloc, realloc, and free functions in VC are implemented using these API functions, while the implementation in BC is quite complicated and seems to have maintained a set of its own functions.
. It is said that the memory-to-memory ratio of BC is faster than that of VC, which is probably the reason.

 

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.