Need help...
I have 3 classes, Manager which holds 2 pointers. One to class A another to class B . A does not know about B and vise versa.
A does some calculations and at the end it puts 3 floats into the clipboard. Next, B pulls from clipboard the 3 floats, and does it's own calculations. This loop is managed by the Manager and repeats many times (iteration after iteration).
My problem: Now class A produces a vector of floats which class B needs. This vector can have more than 1000 values and I don't want to use the clipboard to transfer it to B as it will become time consumer, even bottleneck, since this behavior repeats step by step.
Simple solution is that B will know A (set a pointer to A). Other one is to transfer a pointer to the vector via Manager But I'm looking for something different, more object oriented that won't break the existent separation between A and B
Any ideas ?
Many thanks
David
It kind of sounds like you are writing a producer / consumer pair, who may communicate more easily over a (probably thread-safe) queue of floats.
In other words: the "queue" is like the vector you are currently using. Both A and B will have a reference to this queue. A runs calculations, and writes floats to the queue (possibly three at a time, if that's what you need). B checks the queue, or possibly is "signaled" by A that the queue is ready, and grabs the floats from the queue to process them.
For more info, google (or search Stack Overflow) for "producer consumer" and/or "queue", you'll probably find a lot of useful info.
(e.g. Multithreaded Work Queue in C++)
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