C# .NET - sizeof equiv' for managed objects?

Asked By pk r
02-Mar-04 07:18 AM
I'd like to be able to find the "size" of an managed object, bit like using sizeof (or len in VB). Anyone know how to do this? I suspect there maybe something in the type info perhaps something to do with reflection? BTW I'd like it to included any nested objects too.

Here is what Chris Brumme  Here is what Chris Brumme

02-Mar-04 09:52 AM
of Microsoft says:
"We don't expose the managed size of objects because we want to reserve the ability to change the way we lay these things out.  For example, on some systems we might align and pack differently.  For this to happen, you need to specify tdAutoLayout for the layout mask of your ValueType or Class.  If you specify tdExplicitLayout or tdSequentialLayout, the CLR’s freedom to optimize your layout is constrained.


If you are curious to know how big an object happens to be, there are a variety of ways to discover this.  You can look in the debugger.  For example, Strike or SOS (son-of-strike) shows you how objects are laid out.  Or you could allocate two objects and then use unverifiable operations to subtract the addresses.  99.9% of the time, the two objects will be adjacent.  You can also use a managed profiler to get a sense of how much memory is consumed by instances of a particular type.


But we don't want to provide an API, because then you could form a dependency over this implementation detail.


Some people have confused the System.Runtime.InteropServices.Marshal.SizeOf() service with this API.  However, Marshal.SizeOf reveals the size of an object after it has been marshaled.  In other words, it yields the size of the object when converted to an unmanaged representation.  These sizes will certainly differ if the CLR’s loader has re-ordered small fields so they can be packed together on a tdAutoLayout type."

Oh well  Oh well

04-Mar-04 07:04 AM
Thanks very much for clearing that up
Create New Account
help
Politics of using the standard library C++ / VB I am doing some coding in my spare time on an open source C++ project of the code is not exception safe. (Certainly no RAII here!) Templates are used a bit, but not heavily. Other than a GUI library there are no third party libraries in a rather dated style. Recently I have been pushing to modernise the code in a bit. Nothing radical. Let's start using a scoped_ptr class to avoid having to carefully delete c++.moderated. First time posters: Do this! ] C++ Discussions Adobe (1) Destructor (1) Exception (1) ValueType (1) Describe (1) Cycle (1) Class (1) Bool (1) Herb Sutter wrote some articles on gil / Generic+Image+Library But you will also find counter-examples, e.g., google a bit for EASTL (EA = electronic arts; game company). - - [ See http: / / www.gotw.ca / resources / clcm.htm Wextra -Wunused-variable -Winit-self -Wunused -Werror -Wparentheses -pedantic -Weffc++ * / namespace containers { / * * * @cond * / template<typename ValueType> struct List; template<typename ValueType> struct ListIndex; template<typename ValueType> struct ListNode { public: friend struct List<ValueType> ; friend struct ListIndex<ValueType> ; private: ListNode<ValueType> * _previous
gemeint "Das * *müßte* * eigentlich mit WMI gehen". No comment. Mit bestem Dank im Voraus Wolfgang VB.NET - German Discussions GetSecurityDescriptorBinaryForm (1) IsSddlConversionSupported (1) NullReferenceException (1) CommonObjectSecurity (1) NativeObjectSecurity (1) FlagsAndAttributes (1 Win-API?s arbeiten. Viele Fragen im Netz, aber wenig brauchbare Antworten. Die Doku in VB ist höchst akademisch und ohne Beispiele, die meist mehr sagen als alles übrige. Eine Doku hier aber einen neuen Thread öffnen werde. Noch eine Frage: Gibt es ein Forum für VB Net, in dem ich Dich ev. auch wiederfinden kann? Danke, Wolfgang Am 17.02.2011 85).aspx Weiter bin ich noch nicht gekommen. Nur "nebenan" in m.p.dotnet.languages.vb In einem Forum bin ich nicht. Ich hatte nach Abschaltung des MSFT Newsservers keine Lust lesen. Au?erdem de.comp.lang.misc. Ein Eintrag auf Einrichtung einer Gruppe f?r VB.Net unter der de.comp-Hierarchie wurde gestellt, ich muss aber zugeben, dass ich den viewtopic.php?p = 762&sid = 7fe7dda9a1d3e9279947210fa25407f7 ansieht, scheint 8 der richtige Wert f?r 64-Bit-Plattformen und 5 der richtige f?r 32-Bit-Plattformen zu sein. Es steht sogar ein Kommentar dabei, dass das so ist. Ich habe Armin Zingler: H?tte ich nicht machen sollen. Habe es jetzt mal f?r 32-Bit kompiliert. Der richtige Wert ist 6 (nicht 5). Ist aber auch logisch, denn die Deklaration
Cost of deleting a null pointer C++ / VB Recently, someone was doing some profiling of our code, and found that code essentially like time posters: Do this! ] C++ Discussions Visual Studio 2008 (1) A. McKenney (1) Destructor (1) ValueType (1) Describe (1) Class (1) Bit (1) Otherwise (1) Errr. . . . Careful - -- though maybe my comment could fall in the "nitpicking" category the standard handy) this detail is unambiguously defined in the standard, and taking a little bit (or a lot) of time does not disqualify from "having no effect". With that said 00401122 test ebp, ebp 00401124 je main+126h (401136h) 00401126 mov ecx, ebp 00401128 call ValueType::~ValueType (401540h) 0040112D push ebp 0040112E call operator delete (401732h) 00401133 add esp, 4 delete p2 00401136 test ebx, ebx 00401138 je main+13Ah (40114Ah) 0040113A mov ecx, ebx 0040113C call ValueType::~ValueType (401540h) 00401141 push ebx 00401142 call operator delete (401732h) 00401147 add esp, 4 delete pb
with indexers, destructors, or types. In C#, the static keyword indicates a class variable. In VB, the equivalent keyword is Shared. Its scoped to the class in which it occurs. Example is assumed. Answer2 8000 Answer3 The business logic is the aspx.cs or the aspx.vb where the code is being written. The presentation logic is done with .aspx extention. How trace to true in the line in the html format of the page. %@ Page Language = ”vb” trace = ”true”AutoEventWireup = ”false” Codebehind = ”WebForm1.aspx.vb” Inherits = ”WebApplication2.WebForm1?&gt; 2. You can enable the debugging in the application level for interop between different .NET languages - for example allowing a C# class to inherit from a VB class. • 07. What is IL? • Ans : IL = Intermediate Language. Also known as MSIL (Microsoft Intermediate that is allocated and de-allocated by the .NET runtime's garbage collector. C# and VB.NET data is always managed. VS7 C++ data is unmanaged by default, even when using classes written in other languages - for example, a managed C++ class can inherit from a VB class. An example of a restriction is that a managed class can only inherit from debug" attribute in < compilation > section to "true" as show below: < configuration > < system.web > < compilation defaultLanguage = "vb" debug = "true" / > . . . . . . . . . < / configuration > • This case-sensitive attribute 'debug tells ASP.NET to generate symbols for
language? Are efforts being to made to support these types as constraints? C# Discussions System.ValueType (1) MyEnum.Value1 (1) ValueType (1) LINQ (1) VB (1) Monitor.Enter (1) System.Object (1) System.Int32 (1) On Thu, 17 Apr 2008 09:31:03 -0700, PIEBALD I guess I'm a bit confused about the relationship between C# version and specification version. I'm looking at "Standard type. A boxing conversion exists from any non-nullable-value-type to object, to System.ValueType and to any interface-type implemented by the non-nullable-value-type. Furthermore an enum type as a constraint. System.Enum, in spite of being called a class, inherits from ValueType. It's clearly _not_ a normal class, and isn't really a reference type. I only reference types should be usable as specific types for a constraint. It gets a bit confusing in the sense that the System.Enum type _is_ a valid type to use which all enum-types are derived. The type System.Enum inherits from the type System.ValueType ( = A74.1.1), which, in turn, inherits from type object. At run-time, a value