Jump to content

The function VirtualAlloc( ) is suitable to the following application...?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
krishnampkkm

krishnampkkm

    Newbie

  • Members
  • Pip
  • 7 posts
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( ) ......?





         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

         //Not actually copy..Append my small buffer to  another buffer


         buffer2=buffer1;   //Not correct. append is possible with buffer?


    VirtualFree(buffer1);


 


     } 


     } 



Edited by krishnampkkm, 11 June 2009 - 10:37 PM.


#2
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,715 posts
Dude...use malloc(). It's standard, well-documented, and makes reallocating much easier. And the short answer to your question is no. You can't do realloc() type stuff with VirtualAlloc().
sudo rm -rf /