Windows heap management API

Source: Internet
Author: User

Although we usually writeProgramIt applies for memory using the new or malloc of the c Runtime Library. In fact, the C Runtime Library also calls a set of Apis provided by windows to manage heap memory. Including: heapcreate, heapdestroy, heapalloc, heapfree...

 

To use heap memory, each process needs to call heapcreate to create a private heap object for itself.

Handle winapi heapcreate (DWORD floptions, size_t dwinitialsize, size_t dwmaximumsize)

Floptions: heap option. 0 is input to the C Runtime database. The default value is used.

Dwinitialsize: the initial size. The value is 4096 in the C Runtime Library.

Dwmaximumsize: maximum value that can be allocated. input 0 to the C Runtime database, indicating that a large memory size can be applied.

The function returns a handle, which indicates the heap object, which is required by other APIs.

 

Before the process is destroyed, you should call heapdestroy to destroy this object. This function is very simple. Just pass in the handle.

 

After applying for heapalloc, you can call heapalloc to apply for heap memory.

Lpvoid winapi heapalloc (handle hheap, dwflags, size_t dwbytes)

Hheap: Return Value of heapcreate.

Dwflags: input 0 to the C Runtime database. The default value is used.

Dwbytes: the actual size of heap memory to be applied.

The address of the memory returned by the function.

 

Call heapfree.

Bool winapi heapfree (handle hheap, DWORD dwflags, lpvoid lpmem)

Hheap: the return value of heapcreate, which can also be obtained by calling getprocessheap.

Dwflags: Continue to 0.

Lpmem: The heapalloc return value and heap memory address.

 

These APIs are encapsulated in the C Runtime Library and some features are added.

 

 

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.