Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to determine the size of my class

How to determine the size of my class

Scheduled Pinned Locked Moved C#
tutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Arindam Tewary
    wrote on last edited by
    #1

    Hi Friends How a size of a class can be determined? As an exampleClass A { }
    Class A { int i; public A() { i=10; } }
    Class B { A aa=new A() public B() { } }
    What would be the size of object of type A and B ?? Thanks in advance. :)

    Thanks, Arindam D Tewary

    P 1 Reply Last reply
    0
    • A Arindam Tewary

      Hi Friends How a size of a class can be determined? As an exampleClass A { }
      Class A { int i; public A() { i=10; } }
      Class B { A aa=new A() public B() { } }
      What would be the size of object of type A and B ?? Thanks in advance. :)

      Thanks, Arindam D Tewary

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Unfortunately, there's no quick and easy way (unless you're using Mono where Marshal.SizeOf returns the size of a type in managed code). Common methods for working with size information include using GC.GetTotalMemory, but this is not fine grained enough for the type of detail you want. A better alternative is to use the .NET profiling API. Unfortunately, this means that you are probably going to get down and dirty with C++.

      Deja View - the feeling that you've seen this post before.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups