LPVOID buffer1 = VirtualAlloc(NULL, 1048576 ,MEM_COMMIT,PAGE_READWRITE); // 1048576 = 1MB
Here I allocated memory of 1 MB.And in my application my data is 512 bytes blocks....So I've to check some conditions if that satisfies then that data block must copy to buffer.And when the buffer fills full(1 mb totally used ) I will copy that to another buffer and frees the Allocated buffer1.
I wanna append small small data blocks to the buffer of 1 mb. How can I do this..Is it possible with VirtualAlloc( ) ......?
Code:Assume data size =512 bytes while( some coditions) { if( buffer1 is not fully used) { copy 512 bytes data to buffer1 } else { LPVOID buffer2 = VirtualAlloc(NULL, 1048576 ,MEM_COMMIT,PAGE_READWRITE); // 1048576 = 1MB //copy to buffer2 buffer2=buffer1; VirtualFree(buffer1); } }