Wofür muss ich VirtualAlloc / VirtualAllocEx verwenden?

Wofür muss ich VirtualAlloc / VirtualAllocEx verwenden?

Ein Beispiel, ein Fall, den ich gefunden habe: Wenn ich 4 GB virtuellen Speicher zugewiesen habe, wenn ich nicht alle verwende, dann verbrauche ich keinen physischen Speicher, und wenn ich die Größe meines Arrays ändere, kann ichSie müssen keine alten Daten neu zuordnen und kopieren zu neuem Array.

struct T_custom_allocator; // which using VirtualAllocEx()
std::vector<int, T_custom_allocator> vec;
vec.reserve(4*1024*1024*1024);  // allocated virtual memory (physical memory is not used)
vec.resize(16384); // allocated 16KB of physical memory
// ...
vec.resize(32768); // allocated 32KB of physical memory 
                   // (no need to copy of first 16 KB of data)

Und wenn ich Standard-Allokator verwendet habe, habe ichDaten müssen kopiert werden wenn ich die Größe ändere:

std::vector<int> vec;
vec.resize(16384); // allocated 16KB of physical memory
// ...
vec.resize(32768); // allocated 32KB of physical memory 
                   // and need to copy of first 16 KB of data

Oder mit Standatd Allocator, ichmuss 4GB ausgeben des physischen Gedächtnisses:

std::vector<int> vec;
vec.reserve(4*1024*1024*1024);  // allocated 4GB of physical memory
vec.resize(16384); // no need to do, except changing a local variable of size
// ...
vec.resize(32768); // no need to do, except changing a local variable of size

Aber warum ist das besser als realloc ()?http://www.cplusplus.com/reference/cstdlib/realloc/

Und gibt es noch andere Fälle, in denen VirtualAlloc [Ex] mit Vorteilen verwendet werden kann?

Antworten auf die Frage(2)

Ihre Antwort auf die Frage