Results 1 to 12 of 12

Thread: How much memory do classes use?

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2002
    Location
    Brisbane, Australia
    Posts
    34

    Question 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

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2002
    Location
    Brisbane, Australia
    Posts
    34
    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

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Unless they are shared then I think they are overhead for each instance because each instance holds different values.

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2002
    Location
    Brisbane, Australia
    Posts
    34

    Unhappy

    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

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    So what overhead do you want to know? What overhead is there other than the memory the instance takes?

  7. #7

    Thread Starter
    Member
    Join Date
    Aug 2002
    Location
    Brisbane, Australia
    Posts
    34
    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

  8. #8
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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?

  9. #9

    Thread Starter
    Member
    Join Date
    Aug 2002
    Location
    Brisbane, Australia
    Posts
    34
    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

  10. #10
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    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.

  11. #11

    Thread Starter
    Member
    Join Date
    Aug 2002
    Location
    Brisbane, Australia
    Posts
    34
    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

  12. #12

    Thread Starter
    Member
    Join Date
    Aug 2002
    Location
    Brisbane, Australia
    Posts
    34
    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
  •  



Click Here to Expand Forum to Full Width