PC Review


Reply
Thread Tools Rate Thread

custom memory management

 
 
Wiktor Zychla [C# MVP]
Guest
Posts: n/a
 
      15th Nov 2007
suppose I implement a custom caching mechanism for my custom ORM
implementation. suppose I'd like the client code to be able to define the
maximum amount of memory the cache is allowed to occupy.

however, I have no idea how from within the code I can even retrieve the
amount of memory an object takes. the System.GC.GetTotalMemory method seem
to retrieve the total amount of allocated memory while I would be interested
in monitoring the memory usage for a selected object.

what I need is just a right direction of research.

Thanks in advance
Wiktor Zychla

 
Reply With Quote
 
 
 
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      15th Nov 2007
Wiktor,

The two ways I could think of doing this would be to hook into the
debugging interface in the CLR, or to provide a custom host which would be
able to report the memory consumed by your particular object(s).

The thing is though, why the need for this kind of mechanism? It's
surely more trouble than it's worth, and there is usually not a justifiable
need (not saying yours isn't, but it would help to know why, given that you
have GC to take care of memory management issues for you).


--
- Nicholas Paldino [.NET/C# MVP]
- (E-Mail Removed)

"Wiktor Zychla [C# MVP]" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> suppose I implement a custom caching mechanism for my custom ORM
> implementation. suppose I'd like the client code to be able to define the
> maximum amount of memory the cache is allowed to occupy.
>
> however, I have no idea how from within the code I can even retrieve the
> amount of memory an object takes. the System.GC.GetTotalMemory method seem
> to retrieve the total amount of allocated memory while I would be
> interested in monitoring the memory usage for a selected object.
>
> what I need is just a right direction of research.
>
> Thanks in advance
> Wiktor Zychla


 
Reply With Quote
 
Ben Voigt [C++ MVP]
Guest
Posts: n/a
 
      15th Nov 2007

"Wiktor Zychla [C# MVP]" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> suppose I implement a custom caching mechanism for my custom ORM
> implementation. suppose I'd like the client code to be able to define the
> maximum amount of memory the cache is allowed to occupy.
>
> however, I have no idea how from within the code I can even retrieve the
> amount of memory an object takes. the System.GC.GetTotalMemory method seem
> to retrieve the total amount of allocated memory while I would be
> interested in monitoring the memory usage for a selected object.


First you must define the boundary of your object. Is it:

(A) the memory block on the heap which the reference points to
(B) the set of all blocks reachable from that object (i.e. consider the
object as a GC root)
(C) the set of all blocks which could be freed if the object was eliminated
from the cache
(D) something else

>
> what I need is just a right direction of research.
>
> Thanks in advance
> Wiktor Zychla



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vista runs out of physical memory when working with files > 1GB - memory management issue? Robert Janik Windows Vista Performance 2 21st Apr 2010 06:03 AM
Let's discuss XP memory management (CUSTOM pagefile, algorithms, etc). Jim Lewandowski Windows XP Performance 3 1st Mar 2006 12:52 AM
Memory Management, Free Memory, Available Memory =?Utf-8?B?RkI=?= Microsoft Windows 2000 1 11th May 2005 07:52 PM
.Net memory management. Hadi Microsoft Dot NET 2 23rd Mar 2004 10:39 AM
memory management (vb.net and vb6) Chad Microsoft VB .NET 8 22nd Sep 2003 03:18 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:30 AM.