Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

May be that I am missing something, but I don't see any different between a class instantiated in the regular way #1

Open
netcorefan1 opened this issue Feb 27, 2021 · 0 comments

Comments

@netcorefan1
Copy link

Hello,
I become curious after discovering your library and decided to give it try.
Problem is that I am unable to see any difference between your memory pool and the regular instantiation.

public class Foo
{
    public Foo Init(int val)
    {
        SomeValue = val;
        return this;
     }
     public int SomeValue { get; private set; }
}

int i = 0;
while(true)
{
    i++;
    var instance = Pool<Foo>.Get().Init(i);
    //instance.SomeValue = 100;
    Pool.Return(instance);
}

2021-02-27-02-29-15

int i = 0;
while(true)
{
    i++;
    var instance = new Foo().Init(i);
     //instance.SomeValue = 100;
}

2021-02-27-02-25-04

In both the cases, subsequent instantiations does not allocate memory, but I believe this is due to the compile optimization which store the instance in cache and reuse it.
So, I must missing something!
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant