VB.Net what is the fastest way of storing and retrieving two values in memory

Hi Experts.   I have two threads.  The first runs through millions of lines of text looking for certain criteria.  When it finds what it is looking for, it takes two lines of text and stores them.  The second thread must then take the two lines of text and examine them further.
I am looking for the fastest way for the first thread to store them and for the second thread to access them.   There is no key/value situation necessary but the second thread must follow first in first out.   There may be as many as a few hundred thousand pairs of values waiting for the second thread.    Thoughts would be appreciated
LVL 2
PNRTAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
>>I am looking for the fastest way for the first thread to store them and for the second thread to access them.

Use the queue class:
https://msdn.microsoft.com/en-us/library/system.collections.queue%28v=vs.110%29.aspx
Add to the end (enqueue), signal the second thread there are items, in thread 2 remove oldest (dequeue)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AndyAinscowFreelance programmer / ConsultantCommented:
Also look at:
https://msdn.microsoft.com/en-us/library/dd267265%28v=vs.110%29.aspx
for a ConcurrentQueue.

Both links have details and example code.
0
PNRTAuthor Commented:
Thanks for the reply.   I looked at the queue but wondered about the fact that I was storing a pair of values.
String 1 and string 2.     I suppose I would join them and then split them to process them.  But would these actions not
make the entire process slower than another collection type?
0
Michael FowlerSolutions ConsultantCommented:
If using the queue just remember it is not threadsafe and so also have a look at the Synchronized Queue wrapper.
https://msdn.microsoft.com/en-us/library/system.collections.queue.synchronized.aspx
0
AndyAinscowFreelance programmer / ConsultantCommented:
    class Program
    {
        static void Main(string[] args)
        {
            Queue<foo> qf = new Queue<foo>();
        }

    }

    public class foo
    {
        public string s1, s2;
    }

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.