0

In the following part of my UWP application, I have a performance bottle-neck of creating a lot of large TIFF files. Is there any way to make it run faster without too many conversions and data copies? Due to platform restrictions, I am not allowed to use fopen (access denied).

std::ostringstream output_TIFF_stream;
TIFF* ofo = TIFFStreamOpen("MemTIFF", &output_TIFF_stream);
...

TIFFWriteRawStrip(ofo, 0, currentFrame->image, bufferSize);

TIFFClose(ofo);

auto str = output_TIFF_stream.str();
auto size = str.length();

unsigned char* chars = (unsigned char*)str.c_str();
auto byteArray = ref new Array<unsigned char>(chars, size);

DataWriter^ dataWriter = ref new DataWriter();
dataWriter->WriteBytes(byteArray);

IBuffer^ buffer = dataWriter->DetachBuffer();

create_task(_destinationFolder->CreateFileAsync(fileName))
    .then([](StorageFile^ file) {
       return file->OpenTransactedWriteAsync();
    })
    .then([buffer](StorageStreamTransaction^ transaction) {
        create_task(transaction->Stream->WriteAsync(buffer)).wait();
        return transaction;
    })
    .then([](StorageStreamTransaction^ transaction) {
        return create_task(transaction->CommitAsync());
    })
    .wait();

I have tried broadFileSystemAccess but it has same problem. fopen still doesn't work.

7
  • A common way is to cut the data in to small parts when you trying to do something with it. If you are looking for best performance, I think using win32 API should be better than native UWP file API. Commented Aug 23, 2022 at 6:21
  • But I need Windows Store in-app purchas and I am not sure if it is possible with WIN32. Commented Aug 23, 2022 at 9:31
  • Well, then just try to use smaller data instead of a huge one. Commented Aug 24, 2022 at 5:48
  • There is another option that you can check once you have time. Have you ever heard the Windows APP SDK application? That kind of app could use desktop API and the WINUI library at the same time. Which I think is better for such scenario. It can be upload to the store and use the in-app purchase function as well. Commented Aug 24, 2022 at 5:48
  • @Ax1le Are you sure that Windows APP SDK supports monetization? I can't find any mention about it. Commented Aug 24, 2022 at 6:13

2 Answers 2

0

I haven't found any way to speed up I/O operations in UWP. If you are writing an I/O speed critical application. I recommend using WPF or if you friendly with WRL, then the new Windows APP SDK.

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

Comments

0

For posterity, it is actually possible to use fopen and friends within the ApplicationData folders. This is C++/WinRT code, which can be easily adapted to your needs:

#include <winrt/Windows.Storage.h>

using namespace winrt;
using namespace Windows::Storage;

// Get the app's temp folder
const StorageFolder temp = ApplicationData::Current().TemporaryFolder();

// You can actually create the file through C APIs directly.
// However, copying it to a folder outside of the ApplicationData
// folders requires going through StorageFile anyways, so this
// makes things faster
const StorageFile file = temp.CreateFileAsync(L"bleh.txt").get();
const hstring path = file.Path();

// ...
// Do whatever you want now that you have the file path
// ...

// You can now copy your file to the destination folder, and even
// work on the newly created copy. Keep in mind however, that C APIs
// won't work if the destination folder is not within ApplicationData
const StorageFile copied = file.CopyAsync(destination).get();

// Delete the temp file now that we're done
temp.DeleteAsync().get();

2 Comments

ApplicationData folder is useless for my case. I cannot copy terabytes of date between user and ApplicationData folder
In that case there's also the *FromApp Win32 APIs, which can work if you can work with a Win32 handle. learn.microsoft.com/en-us/uwp/win32-and-com/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.