Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The best method to send images interactively from Haskell backend to Qt QUI

I'm building an application consisting of two parts: QtQuick GUI (C++) and Haskell back-end processing the images using repa and accelerate packages.

I want to interactively display images in GUI. I would love not to copy the data but use some kind of shared memory or any other mechanism, which would allow me to gain the most performance.

What is the best way to "transfer" and display these images interactively in C++ GUI?

I heard about HQK and qtHaskell, but it supports only qtquick up to v4.8 (and we need v5.0 - v5.2)

like image 937
remdezx Avatar asked Oct 21 '22 21:10

remdezx


2 Answers

I'm not sure about Haskell but in lablqt (my library for building QtQuick+OCaml applications, http://kakadu.github.io/lablqt/) I would try this method:

  1. We store image in OCaml/Haskell side as a mutable array of chars (in OCaml it is called string) and we prevent GC from moving this value.
  2. In C++ side we store address of our image and us it to build QString. I don't expect any copying because QString uses copy-on-write.
  3. PROFIT

Maybe this approach sucks because if we will need resize image, GC will instantiate new image, copy old to new one and after that we will need to update pointer to image in C++ side.

Excuse me, in my idea will be unusable.

like image 193
Kakadu Avatar answered Oct 28 '22 16:10

Kakadu


Hm, could you use mmap? There is vector-mmap for Haskell which maps a file into a (shared) memory read only or as mutable vector.

like image 36
MichaelO Avatar answered Oct 28 '22 14:10

MichaelO