Jump to content

Memory mapped files, Windows


Recommended Posts

Supposedly there are Labview tools available at

http://www.lvs-tools.co.uk/software/utilities/

But whenever I try to register or login, nothing happens.  (Also, I try to think, but nothing happens.)  Are there any other Labview codes that use the Windows Memory-Mapped Files functions, or should I just reinvent this wheel?  By the way, here is a Microsoft document on the subject: https://msdn.microsoft.com/en-us/library/ms810613.aspx

Link to comment

There's another way to achieve (almost) memory-mapped files.

https://msdn.microsoft.com/en-us/library/windows/desktop/aa364218(v=vs.85).aspx

If you read from (or write to) a file, Windows automatically memory-maps that portion of the file as long as RAM is available for it.  Although this mapping is not forced (it can be negated by other processes requesting RAM - then disk write and read is via disk and a lot slower) it can still be of great use.  If you need very fast write speed or read / write speed, pre-write (or pre-read) the file before your actually important work.  Chances are that Windows will already do this in memory but with the added benefit of eventually persisting it to disk.  If you want to purposefully AVOID persisting to disk, then just ignore my entire post. :P

Link to comment
  • 4 years later...
Posted (edited)

Update:  I compiled an executable with ShaunR's help.  My LabVIEW VI (LV 2017) communicates fine with a simple C++ program, but my executable doesn't.  I found a workaround (turn the "keep it simple" boolean off, to use the workaround).  Still, I'd like to understand.

The C++ sharmemtest.zip uses Microsoft Visual Studio 2015 and boost (version 1.76.0, if it matters).

 

 shmem__testrd.png.b896c91964ca952ef8286603f704a76e.pngshmem__testrd1.png.7a5bd228a8e23c6a86c396c450b7bb29.png

sharmemtest.zip shmem_testr.vi

Edited by torekp
Link to comment

Are you using LabVIEW 64 bit or 32 bit?

Generally speaking, if the other program creates the mapping then you should only open it instead of creating it so it may depend on which program you are running first (you create a file mapping in that example). Note there is no option to "Open Or Create" in the LV API as you have used in the cmd prompt software.

Running your command prompt software first and reading with the following works fine for me in both the dev environment and as an executable (although it's LabVIEW 2021 32 bit since I don't have 17 installed).

 image.png.408538b6e615ee41e9c38852455b1188.png

  • Like 1
Link to comment

Thanks.  I'm using 64-bit LabVIEW and 64-bit Visual Studio executable.  LabVIEW runs first and creates the memory map, but I don't know how to "Open" in C++ other than "Open or Create".  Since the map name is given, I figured "open or create" sounds appropriate.

Link to comment
2 hours ago, torekp said:

Thanks.  I'm using 64-bit LabVIEW and 64-bit Visual Studio executable.  LabVIEW runs first and creates the memory map, but I don't know how to "Open" in C++ other than "Open or Create".  Since the map name is given, I figured "open or create" sounds appropriate.

I did find a bug for 64 bit that caused mapping to fail, sometimes, in later LabVIEW versions (it's written in 2009). There will be a new version in the next couple of days that I can test with your cmd-line software so keep watching.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.