开发者

Pass by Value or Reference to custom data structure?

开发者 https://www.devze.com 2023-04-05 05:04 出处:网络
I am working on a program that will take the data from your car and display it on a virtual gagae board.I am rearchitecting the software and planning to apply new techniques I have learned Like using

I am working on a program that will take the data from your car and display it on a virtual gagae board. I am rearchitecting the software and planning to apply new techniques I have learned Like using the Composite pattern for organizing my drawable objects.

My question is my graphics are backed by a data set which has the current snap shot of my car's status. Should I pass the pointer to the value in my data set when I initialize my drawable object or should I pass the actual value to it through a buffer when I call my drawable object's update function. If I pass a pointer to the drawable it would grab the value when I call the update function but at the same time I would have to provide the object with the means to beable to lock the function causing my dataset to miss a possible value insertion from the hardware. If I pass by value directly to the update function it I can separate the thread locks from the actual drawing but might take a bit more time for the graphics to get the value. Also if I pass by value w开发者_JS百科ould it be more beneficial to copy the whole data set into a buffer regardless of how many parameters were just updated.

right now as I have it the software is set up to have a buffer inbetween the graphics and the dataset so as the dataset gets updated that value is passed into the buffer to be drawn to the screen. The reason why I'm trying to rewrite the software is cause this method seems to be to slow for me.

So programming gurus which way sounds better.


I would queue up all updates from the hardware and only process them, and subsequent updates, against the dataset and display when the display has finished its inital, full rendering of the complete backup dataset. The only locks needed, if any, would be on the producer-consumer queue where the updates come in from your hardware-reading thread.

Rgds, Martin

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号