Screen / Memory Synchronization Application in Symbian Programming 2005-01-12 Views: 89
Text / peter jiang
Memory as the most valuable resources in Symbian programming, we must use it in programming, it is best not to use. Of course, everyone knows that it is not possible to program any memory, just like Even if you have a grower, you have a bottom line. So what is the bottom line in Symbian? The answer is the mobile phone screen. Since the display area is limited, the contents of its display must be limited, then we can implement precise use of memory resources as long as we keep the memory and screen synchronization.
Accurately utilizing memory is an exact definition of the life cycle of an object to minimize it.
In this question we divide the object into two: (1) Automatic variables defined in the function as a member variable (2) of the class member.
Divide memory management into two questions: (1) When to assign (2), when is deleted.
Member variable automatic variable allocation Our most common way is to distribute a one-time constructor in a constructL ()). Obviously sometimes all objects can be used, since it does not use waste. See Since the 16 military decomposition is not all objects to be used, there must be some objects to lose the sense of use before the designer function, then we need to use a method to determine the object of the loss of use. And then delete them, I think it is quite a good choice to define a status code (icrrentView). I do this in the code below. It will also encounter the same problem as a member variable, but the process of function work is basically linear. If you lose your value, you will delete it. But remember, if an object is deleted, but point to its pointer still exists, then this pointer It should be set to NULL to prevent illegal access or twice deletion. (Refested on Section 8 and 10 Army)
We combine two examples:
The first is the screen synchronization of view (view)
Void cxxxappui :: constructL () {// ⋯⋯⋯⋯⋯⋯ .. icrrentView = enone; // icrrentView is a TViewID enumeration type. Represents the current view status, the initial value is empty (ENONE) CHANGEVIEWL (EmainView); // EmainView is the main view status, that is, the initial view of the program load //}
Here I don't use common ways to assign all member variables in the constructL () function, but to initialize a status variable (icrrentView), then pass to a ChangeViewL's private function, let ChangeViewL delete according to the status of the current view. The member variable of the current view, initializes the member variable of the new view, which is obvious for memory savings.
void CXXXAppUi :: ChangeViewL (TViewId aNewView) {if (aNewView == iCurrentView) // new view state == current view state return; switch (iCurrentView) // delete the current view based on state {case EMainView: RemoveFromStack (iAppView); / / iAppView is a view class for initial view delete iAppView; iAppView = NULL; break; case EWordListView: RemoveFromStack (iListboxView); // list view delete iListboxView; iListboxView = NULL; break; case eNone: default: break;} switch ( aNewView) // create a new state based on the incoming aNewView view {case EMainView: iAppView = CXXXAppView :: NewL (ApplicationRect ()); AddToStackL (iAppView); break; case EWordListView: iListboxView = CWordstoreListboxView :: NewL (ClientRect ()) AddTostBoxView; Break; Case Enone: Default: Break;} icrrentView = anewview; // Update Current View} About Listbox screen synchronization
Symbian's ListBox sample is simple and easy to understand, and unfortunately, code readability and operational efficiency have irreparable contradictions, especially in Symbian's resource resource-limited devices. Let's take a look at Symbian sample code:
void CCustomerstoreListboxView :: SetListItems (CDesCArrayFlat * aNewItems) {CTextListBoxModel * model = iListBox-> Model (); model-> SetItemTextArray (aNewItems); // specified length and content Listbox model-> SetOwnershipType (ELbmOwnsItemArray) through the array; iListBox-> HandleitemadditionL (); if (AnewItems-> count ()> 0) {ilistbox-> setcurrentItemIndexandDraw (0);} // ⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯}
Simply understand, accept a descriptor array, pass it to listbox, and I do this, until one day I feel that the length of the array may exceed 100 or more. I have no real machine to be used to debug, but who can imagine an up to 100 Listbox may give a catastrophic consequence of a mobile phone. Although only three lines of lists can only be displayed on the screen, the quantity in memory we have no control. Solution Theory is very simple (because actually operates, it is more troublesome), maybe you have already thought that the principle is to keep the content in memory and the content on the screen.
There is a virtual function called Handlescrolleventl in the CEIKListBox class to listen to the up and down scroll of the scroll bar. Do not use the ListBox class provided by Symbian to implement the definition of Handlescrolleventl by inheritance.
void CXXXListbox :: HandleScrollEventL (CEikScrollBar * aScrollBar, TEikScrollEvent aEventType) {Index = CurrentItemIndex (); // Get current index value Listbox switch (aEventType) {case EEikScrollDown: // // scroll down the first read Index 1 ListBox value, delete the Listbox of Index-3. Case EEIKSCROLLUP: // Scrolls // Split // Read the listbox value of the INDEX-1, delete the listbox value of the INDEX 3,}} and this will also modify the database engine (if you read from the database) With the value of Listbox, the functions like getAllCustomes are not available anyway, we need to read the function you read one by one.
The above two examples are similar, in fact, there are many similar applications in Symbian programming, such as this game, I am in Rect (). Itl.ix and Rect.ibr.ix two boundaries add the detection of entering and out of submarine. As for the test of torpedoes, I will think about it. It is possible to use space for time to change time in Windows programming, and we may change to time change space in Symbian. Also, don't believe in the simulator, a very smooth program running in the simulator is likely to be a mess. You can refer to the "Configuring Symbian Wins Emulator" in the following article to configure close to the real device. Finally, I said: "Waste is shameful".