From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Best way to store class instances (or at least their private data) in a file for later use?

Solved!
Go to solution
I've been messing around with this concept for a few hours and haven't found anything conclusive yet. I have a system where I want to store some instances of a particular class (private data has a 2D array, a 1D array, some booleans, some numerics, and a cluster of strings.) for later use. The goal is to store an array of these classes for customization purposes. I've experimented with the OpenG configuration file palette, particularly the "read/write section formatted cluster", but I get strange errors when I change around the private data and try to save the same instance. I was thinking about using the flatten to XML vi and wiring in the array of instances then reading it as an array, but I foresee similar problems. What other options are there? TDMS? An SQLite database? Should I do some further splitting into the very base types and combine them at runtime after reading them in? Any and all suggestions/anecdotes welcome.
0 Kudos
Message 1 of 7
(3,580 Views)
Solution
Accepted by topic author ijustlovemath

LV classes are compatible with the Flatten to XML and Unflatten From XML functions. Have you already tried that approach?

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 2 of 7
(3,567 Views)

I have not. I spent an hour or two implementing the config file approach, so I wanted to be sure I wasn't wasting any more time on an approach that wouldn't work. Would it be a bad idea to simply store the XML string in a key of a regular ini file for later consumption? Speaking mainly from a viewpoint of avoiding lots of clutter in my data directory.

0 Kudos
Message 3 of 7
(3,564 Views)

I don't know about potential performance impacts such approach would result in. That being said, i would always try to keep ini-files as small as possible.

Technically, it should work, but requires quite some mixture between ini-file functions, XML functions and of course the class itself.

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 4 of 7
(3,558 Views)

Good point. I'll probably use separate XML files for each then. I'm going to try this out later today and report back if it works. Thanks!

0 Kudos
Message 5 of 7
(3,554 Views)

I think Write to binary file will work. Please check the attached image. This may solve the problem. But for using unbundle or bundle the class object, that VI should be the part the class.

Message 6 of 7
(3,546 Views)

Impressive first post, Nantha 🙂 To keep the application robust, I think I'd try TDMS (which stores in binary with additional info to make recovery more reliable) before binary, as binary files are prone to bitrot, can't be recovered, and aren't always cross platform.

0 Kudos
Message 7 of 7
(3,534 Views)