LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-16-2006, 04:05 AM   #1
sachitha
Member
 
Registered: Aug 2003
Location: Sri Lanka
Distribution: Redhat 9.0
Posts: 104

Rep: Reputation: 15
Unhappy reducing no: of objects created, to improve performance...


with the original code being the following, can i reduce the no: of times that objects(GifFileSelector objects..) are created in the method 'open()' by using the coding that i have put below???
The objects are not created within a for loop continuously.. so i'm not sure if i can make any change to 'reuse objects'.. (provided this open() method is called several times)

original :
Code:
public class FileMenu extends AbstractMenu
{
	public final int INDEX = 0;
	private static final String TITLE = "File";
	private static final int MNEMONIC = KeyEvent.VK_F;

..........
public void itemSelected(String itemName)
	{
		if (itemName.equals(MENU_ITEMS[0].getName()))
			open();
                    .......
                 }



private void open()
	{
   GifFileSelector g = new GifFileSelector();

            .........
               }
The changes that i made:
Code:
public class FileMenu extends AbstractMenu
{
	public final int INDEX = 0;
	private static final String TITLE = "File";
	private static final int MNEMONIC = KeyEvent.VK_F;
	GifFileSelector g;  //creating GifFileSelector instance

...............

private void open()
	{
	
		if (g == NULL)
		{
			g = new GifFileSelector();
		}
		int selected = g.showOpenDialog(MDIFrame.getDesktop());
		if (selected == JFileChooser.APPROVE_OPTION)
		{
			try
			{

							
			.........	
			}
                               }
                        }

Last edited by sachitha; 08-16-2006 at 04:10 AM.
 
Old 08-16-2006, 07:49 AM   #2
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
Thumbs up

yes, the code you used is what you would typically find in a getter method (beans anyone).

Code:
public GifFileSelector getFileSelector(){
    if (g == null){
        g = new GifFileSelector();
    }
    return g;
}
 
Old 08-17-2006, 02:59 AM   #3
sachitha
Member
 
Registered: Aug 2003
Location: Sri Lanka
Distribution: Redhat 9.0
Posts: 104

Original Poster
Rep: Reputation: 15
so does that mean, that i 'm not making any difference(performance improvement) at all to the code, provided the open method is called more than once???
i mean if the open method is called (more than one picture is being opened at different times) am i not reducing the no: of objects being created ..?
 
Old 08-17-2006, 08:48 AM   #4
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
Quote:
Originally Posted by sachitha
so does that mean, that i 'm not making any difference(performance improvement) at all to the code, provided the open method is called more than once???
i mean if the open method is called (more than one picture is being opened at different times) am i not reducing the no: of objects being created ..?
i said yes in reponse to
Quote:
with the original code being the following, can i reduce the no: of times that objects(GifFileSelector objects..) are created in the method 'open()' by using the coding that i have put below???
 
Old 08-17-2006, 09:46 PM   #5
sachitha
Member
 
Registered: Aug 2003
Location: Sri Lanka
Distribution: Redhat 9.0
Posts: 104

Original Poster
Rep: Reputation: 15
okay.. thanks!
well need a lil clarification... If this particular open() method is called only 'once' , both the original coding and my code will do the same thing , ya?
Since, in the modified code that i put, 'g' will be equal to NULL, the object will be created for the first time ya?
 
Old 08-17-2006, 10:27 PM   #6
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
you are correct
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Have i tried everything to improve my disk performance? drben Linux - Hardware 15 02-07-2006 02:38 PM
How can I improve gnome performance? pfaendtner Linux - Software 16 04-14-2005 11:52 AM
Is there a way to improve java performance? jeffreybluml Linux - Newbie 1 07-10-2004 04:08 AM
How to Improve performance of PC Imran Aziz Linux - Software 3 06-03-2004 02:10 PM
improve scsi hd performance? bdp Linux - Hardware 2 01-12-2004 11:37 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration