mercredi 16 avril 2014

mémoire - c#, évaluation de la dimension d'une instance - Stack Overflow


I know there are some questions about it but I want to consider it from a diffrent perspective. My result after searching for this question was that there cant be an exact way to weight an instance by bit. But isnt there a way to approach a realistic size based on storage information?


For instance:


class Test
{
// Fields
private int high = 7;
private int low = 5;

private int GetHigh()
{
return High; // Access private field
}

private int GetLow()
{
return Low; // Access private field
}

public float Average ()
{
return (Gethigh() + Getlow()) / 2; // Access private methods
}
}

Test a = new Test();
Test b = new Test();
a.Average();

So my actual question is: can we asses the size of instance a (and b) in certain ways?



  • I mean we could simply calculate the fields:


2 int fields = 64 Bit



  • But what about metadata?


  • How / or can we actually weight the methods since they are part of the Class type object. And methods are shared by their instances only differentiated by their this pointer.



Can somebody please help me to get a better understanding of this problem. To make it clear, its not about getting an exact value of bits or a method that can calculate this by manipulating VS. Its more about getting a better understanding of instances saved in memory.



I know there are some questions about it but I want to consider it from a diffrent perspective. My result after searching for this question was that there cant be an exact way to weight an instance by bit. But isnt there a way to approach a realistic size based on storage information?


For instance:


class Test
{
// Fields
private int high = 7;
private int low = 5;

private int GetHigh()
{
return High; // Access private field
}

private int GetLow()
{
return Low; // Access private field
}

public float Average ()
{
return (Gethigh() + Getlow()) / 2; // Access private methods
}
}

Test a = new Test();
Test b = new Test();
a.Average();

So my actual question is: can we asses the size of instance a (and b) in certain ways?



  • I mean we could simply calculate the fields:


2 int fields = 64 Bit



  • But what about metadata?


  • How / or can we actually weight the methods since they are part of the Class type object. And methods are shared by their instances only differentiated by their this pointer.



Can somebody please help me to get a better understanding of this problem. To make it clear, its not about getting an exact value of bits or a method that can calculate this by manipulating VS. Its more about getting a better understanding of instances saved in memory.


0 commentaires:

Enregistrer un commentaire