2

I have no problems implementing the memory mapped file. The question is. Assuming this returns a valid memory view:

void* pBuf = MapViewOfFile(hMapFile, FILE_MAP_WRITE, 0, 0, 0); 

Do I have alternatives to using memcpy to give data to it? For instance can I tell my application to store data in it? I really want something like char* buffer = new char[1073741824] where the new places the data in the memory mapped file. This seems logical. Or will I have to write a wrapper that writes to the memory view using memcpy? that would be disappointing.

1
  • Please don't write the answer in the question - I reverted your edit. If you want to answer the question then do so as an answer. Of course there's no point doing so since you have one answer that is identical to your solution. Commented Sep 12, 2011 at 8:31

2 Answers 2

3

Probably the easiest approach is to use the boost memory mapped file classes which give the additional benefit of being portable.

Sign up to request clarification or add additional context in comments.

Comments

0

You can use the placement new operator or you can cast the address to a structure or class you want to use. The advantage of placement new is that the constructor of the class will be called. If you use from then on that pointer you don't need to copy the data but read and write directly to it.

1 Comment

best answer. same conclusion as me. plus it is the most efficient and least bloated.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.