How to determine the size of an Entitycollection in bytes?

Posts   
 
    
rracer99
User
Posts: 58
Joined: 11-Mar-2007
# Posted on: 22-Mar-2010 17:14:12   

How can I determine the size of an Entity collection and its entities in memory? (adapter)

Thank you

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 22-Mar-2010 17:32:12   

This is very tricky, as you can't measure managed objects size in memory. You can serialize to a memoryStream, but this won't be acurate at all. You can use Marshal.SizeOf to return the unmanaged size of an object in bytes.

Please check this discussion for more info: http://bytes.com/topic/c-sharp/answers/238927-object-size-memory

rracer99
User
Posts: 58
Joined: 11-Mar-2007
# Posted on: 22-Mar-2010 18:21:43   

Will Marshal.SizeOf include nested objects and their properties as well?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39866
Joined: 17-Aug-2003
# Posted on: 22-Mar-2010 18:41:51   

why would you want to know the size in bytes?

Frans Bouma | Lead developer LLBLGen Pro
rracer99
User
Posts: 58
Joined: 11-Mar-2007
# Posted on: 22-Mar-2010 20:03:22   

We were going to run some tests to see memory usage between EntityCollections vs custom classes holding only necessary data for caching purposes.

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 23-Mar-2010 08:10:32   

A work wround is to run your application in both cases, each time loading a colletion of 1000 objects, and check the Windiows Task Manager for memory allocated to the running process of your application. This way you can spot the differences.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39866
Joined: 17-Aug-2003
# Posted on: 24-Mar-2010 09:50:10   

To know the byte sizes, use a memory profiler, like Ants or dotTrace. Also use the latest v2.6 build instead of v2.5 or earlier.

Frans Bouma | Lead developer LLBLGen Pro