public class Players
{
public int GUID { get; set; }
public string Name { get; set; }
public string Country { get; set; }
public Clans Clan { get; set; }
public PlayerType Type { get; set; }
public Groups Access { get; set; }
public int Level { get; set; }
public int RoomID { get; set; }
public IPAddress IP { get; set; }
public bool IsPlaying { get; set; }
public bool IsProtected { get; set; }
public bool IsBanned { get; set; }
public bool IsInvisible { get; set; }
public bool IsOnline()
{
return (IPAddress.Parse("0.0.0.0").Equals(this.ExtIP)) ? false : true;
}
public string GetIP()
{
return this.ExtIP.ToString();
}
}
I have a list that uses the above class and I would like to know how could I keep track of how much memory that list is taking for each new user added or each change made to any user already on it or how to calculate it (if possible explained in an easy maner was never good a math hehe) ?
开发者_如何转开发If there is a simple code that could show me that once the list is updated or a new entry goes in/out I would appreciate as well.
This application runs on linux under mono and uses MySQL as database, I was relying a lot on the database and since I run it on a VPS it was consuming a lot of cpu/memory.
In order to optimize it I am considering loading some data on startup and manage updates every X minutes and only update instantly important data instead of querying the database for most information I need to use.
To start that up I would like to understand a bit more on how I could monitor memory usage and the sorts of lists I have or can use for this.
You could use the GC.GetTotalMemory() Method to log a snapshot point-in-time memory usage:
// Measure starting point memory use
GCMemStart = System.GC.GetTotalMemory(true);
// Perform allocations
GCMemEnd = System.GC.GetTotalMemory(true);
[If the
forceFullCollection
parameter is true, this method waits a short interval before returning while the system collects garbage and finalizes objects]
精彩评论