473,322 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Alternative to Transport Variables

Hi,

I have a main loop like this:

while (true) {
receive();
update();
draw();
}

Each stage (i.e. receive, update, draw) uses info from the previous
stage. I am currently passing this info with "transport variables".
These variables are set in one stage, and in the next, read and
cleared.

I find this very cumbersome and prone to errors (especially if I forget
to clear a variable). Is there some sort of design pattern or idiom
that could help?

Note: Each stage is infact traversing a tree so someLeaf.draw() would
not be called immediately after someLeaf.update().

-Jimmy

Jul 23 '05 #1
2 1286
jimmy schreef:
Hi,

I have a main loop like this:

while (true) {
receive();
update();
draw();
}

Each stage (i.e. receive, update, draw) uses info from the previous
stage. I am currently passing this info with "transport variables".
These variables are set in one stage, and in the next, read and
cleared.

I find this very cumbersome and prone to errors (especially if I forget
to clear a variable). Is there some sort of design pattern or idiom
that could help?


What's wrong with objects?

Assuming your transport var hass class C,
why not write
C receive();
C update( C c ); // returns c;
void draw( C c );

C::~C will of course clear the variable. If copying C is too expensive,
you can implement C as a C_impl* and a share count.

HTH,
Michiel Salters

Jul 23 '05 #2
msalters wrote:
jimmy schreef:
Hi,

I have a main loop like this:

while (true) {
receive();
update();
draw();
}

Each stage (i.e. receive, update, draw) uses info from the previous
stage. I am currently passing this info with "transport variables".
These variables are set in one stage, and in the next, read and
cleared.

I find this very cumbersome and prone to errors (especially if I forget
to clear a variable). Is there some sort of design pattern or idiom
that could help?


What's wrong with objects?

Assuming your transport var hass class C,
why not write
C receive();
C update( C c ); // returns c;
void draw( C c );

C::~C will of course clear the variable. If copying C is too expensive,
you can implement C as a C_impl* and a share count.


Why copy at all then? I suggest passing by reference instead. The
declarations for the functions might look like this:

C receive();
void update(C &c);
void draw(C &c);

And the resulting code would be:

while (true)
{
C c = receive();
update(c);
draw(c);
}

The variable c goes out of scope at the end of the loop body and its
destructor can clean up whatever it needs to. Also, if copying a C
object is expensive, try to facilitate the return-by-value optimization
in the receive function. See FAQ 10.9 for details if you don't know
what that is.

Kristo

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: McKirahan | last post by:
I said I wouldn't use "eval()" anymore but I need help to do it. Below is some stripped-down code (4 lines; watch for word-wrap) extracted from USGA.COM that preloads images: main_nav_home_F1...
115
by: TheAd | last post by:
At this moment I use MsAccess and i can build about every databound application i want. Who knows about a serious open source alternative? Because Windows will be a client platform for some time, i...
0
by: Steve - DND | last post by:
We are continually receiving timeout, and "Unable to write data to the transport connection" errors while using the System.Net.HttpWebRequest class from an ASP.Net web page. Below are the two...
2
by: Janna Deegan | last post by:
Hello all, First off, if there is a better place to post for an answer to this question, please feel free to point me there. I have some very strange behavior happening with my System.web.mail...
2
by: sb | last post by:
As the session variable are not recommended, i search for an alternative to store my classe that i use and that i store in that session variable. is that the context that is the alternative? ...
2
by: Navin Mishra | last post by:
Hi, Can ASP.NET web service account be modified to use TCP transport ? Or is there any example of a .NET web service offering TCP transport ? Thanks in advance and regards Navin
1
by: google | last post by:
I have created a simple HelloWorld application in WSE2.0 SP3. When I browse to the endpoint url over http (e.g. http://localhost/TestService.ashx) the WSDL is fine and I can create a client...
2
by: arkascha | last post by:
Hi , we are looking for an efficient method to transport array structures from a php script to some other engine. Currently we offer phps internal serialize function and (if present) the json...
22
by: Dan Rumney | last post by:
Hi all, I've been writing Javascript for quite a while now and have, of late, been writing quite a lot of AJAX and AJAX-related code. In the main, my dynamically generated pages are created...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.