¿Para qué necesito usar VirtualAlloc / VirtualAllocEx?
¿Para qué necesito usar VirtualAlloc / VirtualAllocEx?
Un ejemplo, un caso que encontré: si asigné 4 GB de memoria virtual, si no los uso todos, no uso la memoria física y si cambio el tamaño de mi matriz,No es necesario hacer una nueva asignación y copia de datos antiguos. a la nueva matriz.
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)
Y si he usado asignador estándar,Necesito copiar de datos cuando hago el tamaño
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
O con asignador de standatd, yodebe gastar 4GB de la memoria física:
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
Pero, ¿por qué esto es mejor que realloc ()?http://www.cplusplus.com/reference/cstdlib/realloc/
¿Y hay otros casos para usar VirtualAlloc [Ex] con beneficios?