|
Overview |
|
|
|
Group |
|
|
|
Quick Info
Windows NT
| Yes
| Win95
| Yes
| Win32s
| Yes
| Import Library
| kernel32.lib
| Header File
| winbase.h
| Unicode
| No
| Platform Notes
| None
|
|
|
HeapCreate
The HeapCreate function creates a heap object that can be used by the calling process. The
function reserves a contiguous block in the virtual address space of the process
and allocates physical storage for a specified initial portion of this block.
HANDLE HeapCreate(
DWORD flOptions,
| // heap allocation flag
| DWORD dwInitialSize,
| // initial heap size
| DWORD dwMaximumSize
| // maximum heap size
| );
|
|
Parameters
flOptions
Specifies optional attributes for the new heap. These flags will affect
subsequent access to the new heap through calls to the heap functions (HeapAlloc, HeapFree, HeapReAlloc, and HeapSize). You can specify one or more of the following flags:
Flag
| Meaning
| HEAP_GENERATE_EXCEPTIONS
| Specifies that the system will raise an exception to indicate a function
failure, such as an out-of-memory condition, instead of returning NULL.
| HEAP_NO_SERIALIZE
| Specifies that mutual exclusion will not be used when the heap functions
allocate and free memory from this heap. The default, occurring when the
HEAP_NO_SERIALIZE flag is not specified, is to serialize access to the heap. Serialization
of heap access allows two or more threads to simultaneously allocate and free
memory from the same heap.
|
dwInitialSize
Specifies the initial size, in bytes, of the heap. This value determines the
initial amount of physical storage that is allocated for the heap. The value is
rounded up to the next page boundary. To determine the size of a page on the
host computer, use the GetSystemInfo function.
dwMaximumSize
If dwMaximumSize is a nonzero value, it specifies the maximum size, in bytes, of the heap. The HeapCreate function rounds dwMaximumSize up to the next page boundary, and then reserves a block of that size in the
process's virtual address space for the heap. If allocation requests made by the HeapAlloc or HeapReAlloc functions exceed the initial amount of physical storage specified by dwInitialSize, the system allocates additional pages of physical storage for the heap, up
to the heap's maximum size.
In addition, if dwMaximumSize is nonzero, the heap cannot grow, and an absolute limitation arises: the
maximum size of a memory block in the heap is a bit less than 0x7FFF8 bytes.
Requests to allocate larger blocks will fail, even if the maximum size of the heap is
large enough to contain the block.
If dwMaximumSize is zero, it specifies that the heap is growable. The heap's size is limited
only by available memory. Requests to allocate blocks larger than 0x7FFF8 bytes
do not automatically fail; the system calls VirtualAlloc to obtain the memory needed for such large blocks. Applications that need to
allocate large memory blocks should set dwMaximumSize to zero.
Return Values
If the function succeeds, the return value is a handle of the newly created
heap.
If the function fails, the return value is is NULL. To get extended error
information, call GetLastError.
Remarks
The HeapCreate function creates a private heap object from which the calling process can
allocate memory blocks by using the HeapAlloc function. The initial size determines the number of committed pages that are
initially allocated for the heap. The maximum size determines the total number
of reserved pages. These pages create a contiguous block in the process's
virtual address space into which the heap can grow. If requests by HeapAlloc exceed the current size of committed pages, additional pages are
automatically committed from this reserved space, assuming that the physical storage is
available.
The memory of a private heap object is accessible only to the process that
created it. If a dynamic-link library (DLL) creates a private heap, the heap is
created in the address space of the process that called the DLL, and it is
accessible only to that process.
The system uses memory from the private heap to store heap support structures,
so not all of the specified heap size is available to the process. For
example, if the HeapAlloc function requests 64 kilobytes (K) from a heap with a maximum size of 64K,
the request may fail because of system overhead.
If the HEAP_NO_SERIALIZE flag is not specified (the simple default), the heap
will serialize access within the calling process. Serialization ensures mutual
exclusion when two or more threads attempt to simultaneously allocate or free
blocks from the same heap. There is a small performance cost to serialization,
but it must be used whenever multiple threads allocate and free memory from the
same heap.
Setting the HEAP_NO_SERIALIZE flag eliminates mutual exclusion on the heap.
Without serialization, two or more threads that use the same heap handle might
attempt to allocate or free memory simultaneously, likely causing corruption in
the heap. The HEAP_NO_SERIALIZE flag can, therefore, be safely used only in the
following situations:
- The process has only one thread.
- The process has multiple threads, but only one thread calls the heap functions
for a specific heap.
- The process has multiple threads, and the application provides its own
mechanism for mutual exclusion to a specific heap.
See Also
GetProcessHeap, GetProcessHeaps, GetSystemInfo, HeapAlloc, HeapDestroy, HeapFree, HeapReAlloc, HeapSize, HeapValidate, VirtualAlloc
| Last news from Greatis Software |
 |
|
Nostalgia .Net |
|
.Net is powerful, but not all-powerful, so sometimes we need to use Win32 API for our .Net applications. It's simple enough with Platform Invoke if you have Win32 skill, but we do not always have time to dig the ancient documentation, declare the special types that are compatible with Win32, find the values of the Win32's constants and so on. Nostalgia .Net offers several simple-to-use classes, and components that will allow you to forget about the headache of Win32 and just use the power of Win32 in your application the same way as you use the native. Net classes. More » |
| Recommended software for developers |
 |
|
Ultimate Pack |
|
Component pack for Delphi and C++ Builder that contains runtime form designer, runtime object inspector, print suite and much more for the very special price. More » |
 |
|
Form Designer .Net |
|
Unique runtime form design solution that allows to edit any form in .Net WinForms application at runtime with full source codes for only 300 euro! More » |
 |
|
Print Suite .Net |
|
Print Suite .Net is a set of components for easy printing texts, images and grids from your WinForms applications. Full C# source codes are available More » |
 |
|
Gradient Controls .Net |
|
Gradient Controls .Net offers controls with gradient background feature. Labels, panels and so on... Full C# source codes are available More » |
 |
|
Greatis iGrid |
|
iGrid plots drawing grid right over your desktop, so you can use it everywhere, with any drawing application without any special plugins for different graphic editors. More » |
All the contacts and projectsDmitry Vasiliev (just.dmitry)
Related LinksSoftware for Visual Studio .NET developers Software for Delphi and C++ Builder developers Software for Visual Basic 6 developers Delphi Tips&Tricks MegaDetailed.NET More Online Helps Win32 Programmer's Reference Win32 Multimedia Programmer's Reference OLE Programmer's Reference Microsoft Windows Pen API Programmer's Reference Microsoft Windows Sockets 2 Reference Microsoft Windows Telephony API (TAPI) Programmer's Reference Unix Manual Pages
|