Preloaded into objects

Source: Internet
Author: User
Object preloaded into Object
Zhang Jianji 01-6-22 03:17:13

In PowerBuilder 5.0 support for the full compilation of code, but used to use this method has a long compile time, the volume of large number of compiled executable files, so in many cases, we still use pseudo-compilation method, It is to compile the PBL file of loading object and source code into PowerBuilder dynamic link library (. PBD). The PowerBuilder dynamic-link library is loaded with a binary representation that matches the source code in the Source library. At run time, objects (including functions) follow the principle of "calling as needed", loading memory from. PBD, which reduces the number of bytes in the executable program, increases the efficiency of execution, and makes it much less likely that the system will need memory swapping because only those objects to be used are instantly loaded into memory, So the application runs faster. But sometimes we also find that the user's response to the system is slow when they open windows, especially when the client's configuration is low. We know that when a program calls a new object, the system is going to each. The object is found in the PBD file, and if the object is inherited by another object, all of its ancestor objects need to be loaded into memory. If the application software is very large, this kind of lookup and loading is obviously time-consuming. Here we introduce a method of preloaded object, which can solve this problem to some extent. Pre-preloaded objects are the time to change the initial loading of an object, which means that the user does not have the response speed required to fashion the object, rather than when the user needs the object to load (such as open a window). Preloaded objects can significantly improve performance, which gives the user the impression that all objects are loaded faster when the user really asks for the system's response speed. The most suitable place to do these pre-installed is in the application Open event. This functionality is not directly available in the PowerBuilder 5.0 development tool, but we can implement it with some simple techniques, which is to use a Non-visual object. We should first know that some objects, such as Non-visual objects, are all loaded into memory when invoked, while others, such as functions, load only the required parts. So using a Non-visual object can be quicker than using a global function, and of course its size and functionality. Instead of having all the objects preloaded in the Open event that you applied, you preinstall into those objects that are most often used as ancestors. The specific approach is to define this Non-visual object as a variable. This Non-visual object remains in memory until the application is finished, which makes the application more compact. Another advantage of doing this is that once you define a pointer to an object as a global variable, you can use that pointer anywhere in the software to refer to the object's constants, functions, and other attributes. The steps are as follows: Step one: Create a preloaded object create a Non_vIsual_object the user object of type, save the object in the name you selected. In this case, Nvo_object_pre_loader is used. In this object, a powerobject array of objects is called ipo_pre_loaded_objects[]. The Powerobject object is the highest level object in the Pow-erbuilder object hierarchy (see "PowerBuilder object-oriented Programming"), so it can be assigned to any PowerBuilder standard or custom object. An integer variable is also indexed as an array, and we call it ii_idx and initialize it to 0. Both of these variables are instance variables. private:/* restrict access to these two variables * * * We assume that the number of objects preloaded is no more than 10, of course, developers can also be adjusted according to the actual situation * * Powerobject ipo_pre_loaded_objects[10] Integer ii_ Idx=0 Note that we should define the size of the array here, so that the object can be reserved for memory and run faster when it is preloaded. Step Two: Create a preloaded function now create a user object function called Nvof_pre_load_object. This function has one argument: Apo_object, which is also the Powerobject type. The code for the function is as follows. /* Function: Nvof_pre_load_object function: To pre_load often used ancestor objects parameter: Power Object apo_object return value: Integer 1: Success,-1: Failure * /ii_idx++/* Assign the object to be preloaded to this array/ipo_pre_loaded_objects[ii_idx]=apo_object/* Verify that the assignment is successful/if IsValid (ipo_pre_loaded_ OBJECTS[II_IDX]) then return 1 else Return-1 End If step three: Create a user event that can be put into the calling user object code to build a code that can be put into a call to a preloaded object on this object. We define an event that uses a "declaration" that will be triggered in the object's constructor event. We can name this user event nvo_ue_declarations and put the following code into the object's constructor event. This.post evenT ("Nvo_ue_declarations") you can put a call to a preloaded object in the Nvo_ue_declaration event. Step four: Preloaded into the object this code exists in the Nvo_ue_declaration event. Perhaps your application requires more or less preloaded objects, and we only assume that there are several common ancestor object classes W_windowbase, Udw_datawindow, Uo_userobjectbase, and M_menubase. These objects represent our window classes, User Object Data window classes, user object classes, and the ancestor objects of the menu class. The code in the Nvo_ue_declaraton event is as follows:/* Declares a local variable to these objects/Windows Lwindow UserObject lUO datawindow lDW Menu lmenu/* For each object that needs to be preloaded, Creates an instance of the object using the CREATE statement and calls the preloaded function to save the instance in memory/* Create an instance of a window base class/* Lwindow=create w_windowsbase Nvof_pre_load_object ( Lwindow)/* Create an instance of a Dataw-indow user Object base class/* Ldw=create udw_datawindowbase nvof_pre_load_object (LDW)/* Create a base class instance of a User object * * LUO =uo_userobjectbase Nvof_pre_load_object (LUO)/* Create a Menu instance * * lmenu=create m_menubase nvof_pre_load_object (lMenu) Generally speaking, Objects that are invoked dynamically are those that are called with a string variable and are not included in the. EXE file. For example, if you open a window with open (Mywin, "My_window"), the My_window window is not automatically included in your EXE file. If compiled into. PBD file, it will be included in the. PBD in the middle. But if you preloaded this object in this way, the window is in the. PBD and. EXE compile technology will be included. Step five: Initialize the preloaded object in order to get the object into memory, there is a final step left. We must load the preloaded object itself into memory. You can choose to do it anywhere before you start working in the frequently used section of your application. Commonly used is in the Applica-tion Open event. The code you need is as follows: Anvo_object_pre_loader=create Nvo_object_pre_loader. This program creates this Non-visual object, which fires the object's declared events, and then pre-installed the objects. The last point to note is that you should not forget to add destroy anvo_object_pre_loader such a statement in your Appli-cation Close event, otherwise this application will cause a so-called memory vulnerability (Memory leak).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.