tags:

views:

44

answers:

2

Let's say you havew a user class. When the user is logged in there are properties representing basic user info, an associated address and, say, 5 profile pictures, the last a generic lsit like this: Private _photos As List(Of Photo). However, instead of carrying the weight of the profile pictures in a session vairable, to reduce resource usage, I only want to populate them if the user needs to acces them. So, for the most part, the generic list of photo's is empty. Will it carry weight anyway? I'm trying to decide if I should just not populate ituntil needed, or if I should create an alternative "light" user class which doesn't have this property.

+1  A: 

Provided the "heavy" properties are using a referenced type that will be allocated on the heap, and the allocation is not made until they are needed, they will have very little overhead. In most languages, the overhead will be platform specific, and usually equal to the size of a memory address (ie: a single pointer length, typically 32bit or 64bit per property).

For example, it looks like you're using VB.NET. The List(Of T)'s overhead will be minimal until you start adding elements to it. Then, you take the hit for each element. The List will allocate some initial buffer of pointers, so you'll get a pointer for the list (32/64bit), and an array to hold pointers, but none filled in. In general, you're not talking about a large amount of memory.

If, however, the properties are a value type (this depends on language a bit), they may get allocated in your class directly. This can cause them to have a high overhead in all cases. This is unlikely to be the case, though, since having "heavy" objects as value/stack allocated types is a bad design to begin with.

Reed Copsey
+1 for mentioning Reference Types.
Randolph Potter
Thank you for the help. This Photo object is actually a class I built myself. It is a reference type but it has properties, some of which are value types, some of which are reference types. So, I'm not sure how the class itself is treated.
donde
As long as you don't create an instance, it'll just be a single IntPtr.
Reed Copsey
A: 

Assuming you are storing the paths in a RDB, the roundtrip time for requesting properties on demand are likely to be larger than just requesting them every time. However, you need to look at your usage: Will it be 9 of 10 times they need the path or 1 / 10?

Try it out both ways in a miniproject and then profile it. This is one of those times where there is no "right" answer.

cwap
Seems like I sorta misunderstood the question. Nevermind :)
cwap