Ignore my last message got the  Anakrino code - Pretty kewl .

Had a closer look at Cache and could not see where it was working out the
size of the items. It gets the memory pressure from the Garbage Collector
and the current Process see below. Then cleans up items from the LRU list
independed of size - it looks like ti mainly depends on time .

Looks like a GlobalMemoryStatusEx call to Kernel32.lib and
Process.WorkingSet  will allow me to use the same memory logic.

Looks like I was in the right track in my last email - I would have thought
that the Cache would have taken the size of the object into account - it
looks like they intended to take this into account  ( from the method names
and structure) account but could not do it :) .

Ben

eg private int GetCurrentPressure() {
        MEMORYSTATUSEX local0;
        long local1;
        int local2;
        int local3;
        int local4;
        uint local5;
        uint local6;
        long local7;
        int local8;

        <{ class ILEngineer::Ops::MSIL::InitObj }>;
        local0.Init();
        if (UnsafeNativeMethods.GlobalMemoryStatusEx(local0) == 0)
                return 0;
        local1 = GC.GetTotalMemory(false);
        local2 = (int) (long) 100 * local1 / this._totalMemory;
        local2 = Math.Min(4 * local2, 100);
        local3 = local2 * local0.dwMemoryLoad / 100;
        if (this._memoryLimit != (long) 0) {
                local4 = UnsafeNativeMethods.GetProcessMemoryInformation(this._pid,
local5, local6, 1);
                if (local4 == 0) {
                        local7 = (ulong) local5 << 20;
                        local8 = (int) local7 * (long) 100 / this._memoryLimit;
                        local3 = Math.Max(local3, local8);
                }
        }
        return local3;
}


-----Original Message-----
From: Moderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED]]On Behalf Of Joel Mueller
Sent: Wednesday, 5 June 2002 1:08 PM
To: [EMAIL PROTECTED]
Subject: Re: [ADVANCED-DOTNET] Size of object


That's the problem, though, isn't it? Every time a GC runs, and you
don't know when that is, your entire cache is cleared out, except for
the objects that you might happen to actually be using at the time of
the GC. Wouldn't it be better to retain the items that were used
most-recently, on the theory that they are more likely to be needed
frequently, and only remove those items if you still don't have enough
memory after removing the infrequently-used items?

If you look at how System.Web.Caching.Cache works using Anakrino [1],
you'll see that it's got quite a lot of code involved with finding out
how much memory is free, and how much is being used, and removing only
expired items from the cache.

It just seems that if your whole cache (aside from any objects actively
being used) goes away on every GC, then it's better than no cache at
all, but not nearly as good as something more intelligent. The trouble
is that it's not very easy to write something more intelliegent, as
there's no easy way to find out either how much memory a given object is
actually consuming, or how much system memory is free.

        - Joel

[1] http://www.saurik.com/net/exemplar/

> -----Original Message-----
> From: Moderated discussion of advanced .NET topics.
> [mailto:[EMAIL PROTECTED]] On Behalf Of Brad Wilson
> Sent: Tuesday, June 04, 2002 4:46 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [ADVANCED-DOTNET] Size of object
>
>
> As I see it, these objects will never get out of gen 0 unless
> they're being held during GC, which should be rare enough
> (don't know the usage pattern, just taking a guess). That
> pretty much guarantees they get collected every time collection runs.
>
> Brad
>
> --
> Read my web log at http://www.quality.nu/dotnetguy/
>
> You can read messages from the Advanced DOTNET archive,
> unsubscribe from Advanced DOTNET, or subscribe to other
> DevelopMentor lists at http://discuss.develop.com.
>
>

You can read messages from the Advanced DOTNET archive, unsubscribe from
Advanced DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to