Windows core programming heap

Source: Internet
Author: User

Heap

1. Default heap of the process

By default, the heap is created by the system before the process starts to run and is automatically destroyed after the process is terminated.

All ANSI functions in windows call Unicode functions. You must access the default heap of the process.

2. Why should I create an additional heap?

1. Protect Components

2. More Effective Memory Management

3. Local access

4. Avoid thread synchronization overhead

5. Quick Release

3. If you create an additional heap

Handle heapcreate (DWORD Floptions, Size_tDwinitialsize, Size_tDwmaximumsize);

Parameter 1 indicates the heap allocation attribute.

Parameter 2 indicates the initialization size

Parameter 3 indicates that the maximum size is increased to 0. If it is 0, it indicates that the memory is automatically increased until it is used up.


Exercise caution when using the heap_no_serialize flag, which will cancel the serialized access to the heap.


Call heapalloc to allocate memory

Lpvoid heapalloc (handle Hheap, DWORDDwflags, Size_tDwbytes);

Parameter 1 indicates the heap handle.

Parameter 2 indicates specifying some flag

Heap_generate_exceptions generates an exception

Heap_no_serialize does not need to be serialized when allocating memory. In the default heap, do not use this flag. Access conflicts may occur.

Heap_zero_memory memory allocated, clear 0

Parameter 3 indicates the size of required bytes.



Adjust the memory block size. Use the following function:

Lpvoid heaprealloc (handle Hheap, DWORDDwflags, LpvoidLpmem,
Size_t
Dwbytes);

Heap_realloc_in_place_only tells the function not to move the memory block.



Obtain the memory block size

Size_t heapsize (handle Hheap, DWORDDwflags, LpcvoidLpmem);


Release memory blocks

Bool heapfree (handle Hheap, DWORDDwflags, LpvoidLpmem);


Destroy heap

Bool heapdestroy (handle Hheap);


4. Other heap Functions

Heap32First

Heap32next

Heap32ListFirst

Heap32listnext


The getprocessheaps function obtains the number of heaps.

Heapvalidate () Heap integrity heapcompact () fragment heaplock, heapunlock

Heapwalk is only used for debugging




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.