locked
Have problem writing file with Metro style C++

    Question

  • when I use DataWriter write something to a file,I found the system will create a tmp file.I want to know if this operation cost much time when I

    storeAsync and flushAsync frequently.The code is just like the following:

    try
    		{
    
    			IOutputStream^ outStream = stream->GetOutputStreamAt(position);
    
    			DataWriter^ dataWriter = ref new DataWriter(outStream);
    
    			dataWriter->WriteBytes(arr);
    			task<unsigned int>(dataWriter->StoreAsync()).wait();
    			task<bool>(dataWriter->FlushAsync()).wait();
    
    			dataWriter->DetachStream();
    		}
    		catch(Platform::Exception^ e)
    		{
    			Platform::String^ text = e->Message;
    		}

    Monday, April 23, 2012 1:40 AM

Answers

  •  Hello,

     

    You can use the GetTickCount() function, like this

     
    template <class Function>
    __int64 time_call(Function&& f)
    {
       __int64 begin = GetTickCount();
       f();
       return GetTickCount() - begin;
    }
    
    
    __int64 elapsed;
    elapsed = time_call([&] { //Lambda expression});

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Jesse Jiang Tuesday, May 1, 2012 8:14 AM
    Tuesday, April 24, 2012 2:39 AM

All replies

  • You could try benchmarking it against some Win32 code.
    Monday, April 23, 2012 9:41 PM
  •  Hello,

     

    You can use the GetTickCount() function, like this

     
    template <class Function>
    __int64 time_call(Function&& f)
    {
       __int64 begin = GetTickCount();
       f();
       return GetTickCount() - begin;
    }
    
    
    __int64 elapsed;
    elapsed = time_call([&] { //Lambda expression});

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Jesse Jiang Tuesday, May 1, 2012 8:14 AM
    Tuesday, April 24, 2012 2:39 AM