≡ Menu

05 VISV Optimizing LabVIEW Class Loading with the Factory Pattern

 

VISV-002 ThumbnailIn this video tutorial, I share with you a technique that I use, when I want to be selective of how LabVIEW child classes load into memory. Specifically, by using the Factory pattern, I can dynamically load a class into memory and create an instance of a child class on-demand.

It’s important to note that LabVIEW loads classes into memory automatically whenever class objects are used in VIs.

To demonstrate these concepts, I am using a code example from VISV 002. Take a look at that video if you want a more in-depth walkthrough of the code. Here, I attack the problem of how to limit loading of classes to only the ones you need for your current application run.

Download Code Used in this Tutorial: (LabVIEW 2009)

About the author: Michael Aivaliotis has been working in the test and measurement industry since 1993 with LabVIEW 3.0. He started his career as a test engineer and quickly fell in love with the graphical programming paradigm that LabVIEW provided. Since then, he’s worked on or developed an incredible number of complex test systems in electronics, semiconductor, automotive, telecom, biomedical and other industries. He’s an Certified LabVIEW Architect and a Certified LabVIEW Instructor. He also has the distinction of being among a select few LabVIEW Champions. In 2002, he created the LAVA Forums which have now become the largest independent online LabVIEW community. Email Me

  • http://twitter.com/jlokanis John Lokanis

    If you don’t want to include the child classes in the EXE but rather provide them as a plug-in component, what is the best way to package them for distribution? (with diagrams removed, typedefs disconnected, etc)

    • http://vishots.com VI Shots

      John. I would build a source distribution for the child classes and just build an executable out of the parent class. I will do a follow up video in the future to cover this use-case.

      • FabiolaDelaCueva

        Michael, did you do this follow up video? Where can I find it?
        Thanks,
        Fab

  • Anonymous

    Michael,

    Wonderful presentation! Clear and effective! I especially like how you showed what is in memory when.

    For clarification:
    This is essentially what Head First Design Patterns terms a Simple Factory (often used, but not included as one of the Gang of Four patterns).
    If you take your method to load an object, put it in a class, make an interface class for that, and call the interface method in your application, you have the Factory Method Pattern, which is one of the Gang of Four patterns.

    I’m looking forward to the next video! Well done!

    Paul

    • http://vishots.com VI Shots

      Thanks for your feedback and clarification Paul. I’ve been using objects in LabVIEW for only a fraction of my entire LabVIEW career. I’m still in learning mode and am constantly pushing myself to explore and learn new patterns.

  • Ray Farmer

    although a child doesn’t start of in memory, once loaded it appears to stay in memory. Can it be unloaded  at the cleanup

    • http://vishots.com VI Shots

      Nope, talk to NI :). There is no way currently to unload a class once it has been loaded into memory.