tags:

views:

133

answers:

1

Before I describe my problem, here is a description of the program I'm writting:

This is a C++ application.

The purpose of my program is to create file on RAM memory.

I read that if specify FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE when creating file it will be loaded direct to the RAM memory.

One of blogs that talk about is this one: http://blogs.msdn.com/larryosterman/archive/2004/04/19/116084.aspx

I have built a mini-program, but it not achieves the goal. Instead, it creates a file on hard-drive on directory I specify.

Here's my program:

void main ()

{

LPCWSTR str = L"c:\temp.txt"; HANDLE fh = CreateFile(str,GENERIC_WRITE,0,NULL,CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE,NULL);

if (fh == INVALID_HANDLE_VALUE) { printf ("Could not open TWO.TXT"); return; }

DWORD dwBytesWritten;

for (long i=0; i<20000000; i++) { WriteFile(fh, "This is a test\r\n", 16, &dwBytesWritten, NULL); }

return; }

I think there problem in CreateFile function, but I can't fix it. Please help me.

A: 

Larry Osterman also mentions:

If you exceed available memory, the memory manager will flush the file data to disk. This causes a performance hit, but your operation will succeed instead of failing.

So the OS creates the file in case it needs to flush the data due to memory limits.

In silico
I think it's not the case. I have more than 2GB RAM free.File I try to create catch few hundreds MB.
I said "in case." Your program does create the file on my system, so I believe this is expected behavior.
In silico