|
-
Oct 13th, 2002, 09:34 PM
#1
Thread Starter
Member
How much memory do classes use?
I am trying to work out how much memory a particular class, I have created, uses. It is a simple class that has about a dozen private variables, a few properties and a few public methods. The thing is that when running my app, there could be up to 10,000 instances of it in memory. My concern is that it will use too much memory. How do I tell what amount of memory my class will use? Do the properties and methods only get set once or are they repeated for each instance and what is the overhead?
Any Clues?
Alan Liddle
-
Oct 13th, 2002, 09:46 PM
#2
I'm not sure what the general overhead of classes is in .NET but you could serialize an instance to a file and see the size of it. That would give you the general size of each instance.
I'm not sure what you mean by this:
Do the properties and methods only get set once or are they repeated for each instance and what is the overhead?
What I would really look at is if you really need 10,000 instances running? Of course I don't know what you are doing so maybe you do need that many, but it seems like an excessive amount that should be avoidable.
-
Oct 13th, 2002, 10:18 PM
#3
Thread Starter
Member
In reference to my comment 'Do the properties and methods only get set once or are they repeated for each instance and what is the overhead?', I was wondering if the properties and methods were an overhead for each instance, or once only for the execution of the application.
Alan
-
Oct 13th, 2002, 11:06 PM
#4
Unless they are shared then I think they are overhead for each instance because each instance holds different values.
-
Oct 13th, 2002, 11:13 PM
#5
Thread Starter
Member
I am thinking that your idea to serialise to a file might not really give me the answer I am after. It will certainly give me an idea of how much memory the data component of the class uses, but will not tell me what the overhead is.
Alan
-
Oct 13th, 2002, 11:17 PM
#6
So what overhead do you want to know? What overhead is there other than the memory the instance takes?
-
Oct 13th, 2002, 11:33 PM
#7
Thread Starter
Member
That's exactly it. I need to know exactly what memory each instance takes up, so that I can work out whether my current approach is feasable.
Alan
-
Oct 13th, 2002, 11:40 PM
#8
Well couldn't you just add up how mean bytes each property takes and total it for what you want? Or if you serialize it then it will be a conservative measure since the serialized version will most likely have a little bit of extra information, but would still give you a ball park figure. Why is it that you need 10,000 instances?
-
Oct 14th, 2002, 12:11 AM
#9
Thread Starter
Member
Don't the actual property functions and methods use up memory too, or is it that for each added instance, we only have to worry about the data component.
The reason for so many instances.... We are developing a contract and forms designer package. Part of our strategy is to have an object for every word in a paragraph, as within a form or contract there can be embedded text boxes, comboboxes, etc within a paragraph. Programming-wise it is very simple to display and print text in this way. My only concern is the memory. 10,000 words is probably an over-estimate, but it is better to be safe than sorry.
Alan
-
Oct 14th, 2002, 12:12 AM
#10
Fanatic Member
Why don't you just write a test app that populates 10,000 classes of the structure you want with random maximum-size data and then see how big it gets? Shouldn't take too long to do that.
-
Oct 14th, 2002, 12:23 AM
#11
Thread Starter
Member
I just got this response from another forum:-
' The properties are unique for each instance (as they have to be, obviously), but the methods are only created once and a pointer to the data that they operate on is passed to them invisibly.
'
But, I might do what you suggest and create a simple app and look at memory usage in Windows Task Manager, Processes tab. I just did the same with MS Word and a 10,000 word document takes about 10mb of memory.
Thanks very much for your help. I really appreciate it.
Avagooday!!!!
Alan
-
Oct 14th, 2002, 01:17 AM
#12
Thread Starter
Member
Have run test program on my Word object. My app only used up 448k more memory for the first 10,000 words (As opposed to 10MB for MS Word) and only increased a further 392k for the next 40,000 words. I am extremely happy!
Alan
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
|