Essentially, will more memory be used by instances of Foo when its value is acquired like this:
public class Foo
{
internal double bar;
double GetBar(){ return bar; }
}
or like this?
public class Foo
{
internal double bar;
}
public static class FooManager
{
public static double GetBar(Foo foo) { return foo.bar; }
}
That is, is memory used per-method per-object or per-type?
The instances themselves only have a single pointer to a table of methods that is loaded with the class, so there isn't extra per-instance overhead for having more methods, only fields.
The second example will use slightly more memory in total because you have definitions for two classes and so more per-class overhead (and as originally written, with FooManager as a non-static class, you need a FooManager instance), but the amount of memory used by each Foo instance is the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With