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_tDwbytes);
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