tags:

views:

30

answers:

2

Using classic ASP, I have something like:

class cUser
   Public function LoadData(p_id)
    * load from database for the user p_ID *
   end function
end class

Now my problem is this: I have a loop to get up to 50 User instances on a single page (fetching form posts lists).

I can get user instance by

dim User1
Set User1 = new cUser

But my question is: How do I see if the user instance has allready been created? Also what is the best way to make this 20 instances? By using User1, User2 etc... or defining instance as User2834 (2834 is users's ID in database)?

As the forum posts can be from same user, I really don't want to make multiple object instances of a cUser class if I allready have this user instance...

Maybe this is a newbee question, I am more used to work with functions than OOP.

Yours

Jerry

+1  A: 

You could use a Dictionary object to cache all your user instances.
If you use the User_ID as the key in the dictonary to can easily check with the .Exists Method of the Dictionary whether you've already loaded the user.

Yots
I have now used a simmular aproach and used a Application object, so I have my users data (the main ones) across pages so I can easily get to this data when needed on pages. But I wonder how much would a 30.000 records application object cost me in CPU and memory (I fear more CPu then memory).
Jerry2
A: 

You could use an array to store your objects and then make a function to look for a specific value (a primary key would be ideal) within your array's objects. This way you would be able to know if the object already exists.

Jason