Results 1 to 2 of 2

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
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Usage per class:
    size of all static properties + code size of all methods and getters/setters

    Usage per instance:
    size of all non-static properties + 4 bytes per virtual function in this class and all base classes + 4/8 bytes for the reference (4 on 32-bit systems, 8 on 64-bit systems) + overhead of allocation (I guess ~20 bytes)

    I think that's it.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

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