The last time I learned about the global memory allocation, in windows, the memory management is divided into two parts. The global memory is the memory managed by the system, so all processes can access the memory, each process has its own memory space, which is the virtual memory space. The virtual memory space is large. When the physical memory is insufficient, the system will save the virtual memory data to the hard disk, so that as long as the hard disk space is large enough, each process can use 3 GB memory. Virtual Memory allocation can be used Program The main way to allocate memory in, such as a large amount of data buffer, Dynamic Allocation of memory space. Using the virtualalloc function to allocate memory is faster than the global memory.
The virtualalloc function declaration is as follows:
Winbaseapi
_ Bcount (dwsize)
Lpvoid
Winapi
Virtualalloc (
_ In_opt lpvoid lpaddress,
_ In size_t dwsize,
_ In DWORD flallocationtype,
_ In DWORD flprotect
);
Lpaddress is the address starting with the specified memory.
Dwsize indicates the size of the allocated memory.
Flallocationtype is the type of memory allocated.
Flprotect is the permission to access the allocated memory.
An example of calling a function is as follows:
#001 //
#002 // allocate virtual memory.
#003 // Cai junsheng 2007/11/20 QQ: 9073204 Shenzhen
#004 void memvirtual (void)
#005 {
#006 //
#007 // allocate the new memory size.
#008 uint nnewsize = (uint) Ceil (1500/1024 .0) * 1024;
#009 pbyte pnewbuffer = (pbyte) virtualalloc (null, nnewsize, mem_commit, page_readwrite );
#010 if (pnewbuffer)
#011 {
#012 // test the virtual memory.
#013 zeromemory (FIG, 1500 );
#014 memcpy (pnewbuffer, _ T ("virtual memory allocated successfully \ r \ n "),
#015 sizeof (_ T ("virtual memory allocated successfully \ r \ n ")));
#016 outputdebugstring (lpwstr) pnewbuffer );
#017
#018 // Delete the allocated memory.
#019 virtualfree (pnewbuffer, 0, mem_release );
#020}
#021
#022}
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/caimouse/archive/2007/11/20/1895301.aspx