Skip to content

ziyasal-archive/obj-pool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

obj-pool

simple object pool implementation

public class Program
    {
        public static void Main(string[] args)
        {
            CancellationTokenSource cts = new CancellationTokenSource();
            
            Task.Run(() =>
            {
                if (Console.ReadKey().KeyChar == 'c' || Console.ReadKey().KeyChar == 'C')
                    cts.Cancel();
            }, cts.Token);

            ObjectPool<TestClass> pool = new TestPool();

            Parallel.For(0, 1000000, (i, loopState) =>
            {
                TestClass mc = pool.CheckOut();
                Console.CursorLeft = 0;
                Console.WriteLine("{0:####.####}", mc.GetValue(i));

                pool.CheckIn(mc);
                if (cts.Token.IsCancellationRequested)
                    loopState.Stop();

            });
            
            Console.WriteLine("Press the Enter key to exit.");
            Console.ReadLine();
            cts.Dispose();
        }
    }

Releases

No releases published

Packages

No packages published

Languages