Red Gate forums :: View topic - Memory size of Boolean
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
ANTS Profiler Previous Versions
ANTS Profiler Previous Versions forum

Memory size of Boolean

Search in ANTS Profiler Previous Versions forum
Post new topic   Reply to topic
Jump to:  
Author Message
palelocust



Joined: 18 Dec 2008
Posts: 1

PostPosted: Thu Dec 18, 2008 4:52 pm    Post subject: Memory size of Boolean Reply with quote

I'm memory profiling an application and as I was scrolling through the data I noticed that System.Boolean objects are showing a size of 12 bytes. I thought, though, the size of a boolean in C# was 1 byte (http://msdn.microsoft.com/en-us/library/eahchzkf.aspx)

So what is causing the extra 11 bytes to show up in Memory Profiler?

Thanks
Back to top
View user's profile Send private message
AndrewH



Joined: 17 Aug 2006
Posts: 137

PostPosted: Fri Dec 19, 2008 11:08 am    Post subject: Reply with quote

Value types like booleans won't show up in the memory profiler unless they have been boxed by .NET, as in all other cases they will be part of other classes and not visible as distinct objects.

A boxed boolean will have 8 bytes of .NET header, 1 byte of boolean and 3 bytes to make the size a multiple of 4 (exactly the same as a class containing a single boolean field). This makes them quite inefficient to store as objects - if you consider the fact that you also need to have at least one reference to this boolean the total memory required is actually 16 bytes per boolean.
_________________
Andrew Hunter
Software Developer
Red Gate Software Ltd.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group