Dan,

Thanks so much for the overview of Identity Map. Each time I sit down  
to learn about DataMapper I'm impressed by how clean and well- 
architected the code is -- it makes me pretty excited that Ruby has DM  
going for it. I appreciate you taking the time to spell out this  
particular facet of DM for me :)

Implementing a WeakHash for the IM appears on the surface to be  
something I'm definitely interested in pursuing -- I think that would  
work out nicely for my game. Resources that are no longer referenced  
by anything other than the IM could be safely released from memory.

That being said, I'm not sure that memory consumption is an immediate  
concern of mine -- ideally I'd probably want the game running on a  
system that has enough memory to keep the entire game in-memory (but  
that may be naive). So with this new information, two things I'm going  
to look into are 1) hacking DM to make the IM global, and 2) writing  
an adapter for a totally in-memory database that serializes itself at  
certain intervals (sounds a bit scary and slow, but maybe fun).

Thanks again,

Brent



On Oct 18, 2008, at 2:34 AM, Dan Kubb (dkubb) wrote:

>
> Hi Brent,
>
>> With the Identity Map pattern, I thought I wouldn't have this problem
>> -- I thought that this would be true:
>>
>>      Player.get(1).object_id == Player.get(1).object_id
>>
>> Not so. I found that I had to do something like this:
>>
>>      repository(:default) do
>>           Player.get(1).object_id == Player.get(1).object_id
>>      end
>
> Think of the Identity Map as a Hash that maps each key to a Resource.
> Whenever DataMapper looks up a Resource by a key it checks the
> Identity Map first to see if it's already been loaded, reusing it if
> it has, otherwise loading the Resource and registering it in the
> Identity Map to speed future lookups.
>
> The reason why this doesn't happen globally is because it would have
> very negative effects for a long running processes.  The reference to
> the Resource object from the IM would never be freed, thus preventing
> them from ever being garbage collected.  Memory usage for the process
> would continue to grow until it consumed all available memory.
>
> Instead what we do is make it so the Identity Map is only in scope
> during the repository block.  This allows proper GC to occur, and
> works well with long running processes.
>
> It may be possible to implement a "global" Identity Map if ruby had a
> decent WeakHash library.  The idea being that if we used a WeakHash
> instead of a Hash, Ruby would be able to GC Resource objects where the
> only remaining reference is from the IM.  However in speaking with
> Sam, the WeakHash libraries he's tried never worked properly.  I don't
> know all the details, you'll have to ask Sam for those. The only thing
> I know is it didn't work as expected.
>
> If you're willing to fix and/or create a working WeakHash library for
> Ruby I'd be interested in looking into a global IM further.  My
> primary concern is that it work correctly and be at least comparable
> in speed to the current IM system which is based on a Ruby Hash.  A
> global IM would likely need to be a plugin rather than replacing
> what's in dm-core because it will need alot of testing and what we
> already have is relatively safe and well proven.
>
> Dan
> (dkubb)
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to