|
-
January 27th, 2010, 09:35 PM
#1
Question about Class and memory usage
Hi everyone,
I am a beginner programmer.
Does a the size of the class affect the memory usage of the application? is it better to break big classes into smaller classes or just group them up into one big class. thanks
-
January 27th, 2010, 11:10 PM
#2
Re: Question about Class and memory usage
just to make things a bit clearer, i have a utilily class that contains various functions for database dependency checkings and datasource substitutions (for datagridviews etc). i am wondering if whether breaking each of these functions into smaller classes rather having them in one chunky class would boost the application performance even by a little bit (or maybe save some memory usage). This thought came into my head because most of the time i am instantiating this class just to use one or two functions inside it. The rest of the functions will never get used during that class life cycle (sorry if i get some terminologies wrong here but i hope i get the point accross).
thanks in advance.
-
January 28th, 2010, 04:36 PM
#3
Re: Question about Class and memory usage
Well, it depends.
Every time you create an instance of the class, you're basically creating a pointer to the class definition. You're not actually creating a copy of the class each time. With that being said, if your class has any value –type variables or variables with a value, then each instance of those variables will eat up space.
A good practice for utility classes is to create a Singleton instance, or use static ("shared") methods that can be used without creating an instance of the class first.
An example of static methods:
Code:
Public Class Utility
Public Shared Function Foo() As String
'Do something
End Function
Public Shared Function Foo2() As String
'Do something
End Function
End Class
And, you can use that class without creating an instance:
Good Luck,
Craig - CRG IT Solutions - Microsoft Gold Partner
-My posts after 08/2015 = .NET 4.x and Visual Studio 2015
-My posts after 11/2011 = .NET 4.x and Visual Studio 2012
-My posts after 02/2010 = .NET 4.0 and Visual Studio 2010
-My posts after 12/2007 = .NET 3.5 and Visual Studio 2008
-My posts after 04/2007 = .NET 3.0 and Visual Studio 2005
-My posts before 04/2007 = .NET 1.1/2.0
*I do not follow all threads, so if you have a secondary question, message me.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|