Raised This Month: $ Target: $400
 0% 

Threaded plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
maitredede
Senior Member
Join Date: May 2005
Old 08-02-2005 , 04:23   Threaded plugin
Reply With Quote #1

Hi

Since I finally managed to make a working little plugin, I'm going to start my database plugin...

Due to the amount of time any query requires, I'd like to thread some parts of my plugin, to avoid lags each time a query is done...

So how should I do to make threaded code for my plugin for both win and linux, and share data between both ? (ex: a chain list, one thread fills it, and another modifies it)

Another question, where can I find all string functions I can use (basics, conversions, comparison...) ?
__________________
make brain && make install
maitredede is offline
theqizmo
Member
Join Date: Oct 2004
Old 08-03-2005 , 03:15  
Reply With Quote #2

For the threads

What I have done in a multi-threaded program is push data onto vector (actually a queue, but who's keeping track, anyway?) in the main thread, and then when I need to use the data in another thread, I create the thread, then read the data from vector, pop the data off, then let the thread close.

This is the best method upon which I came. There may be other methods that are better, but this one works for me.

What sort of string implementation?

Character arrays? STL strings? Or some other implementation of a string class?

Here is a list of some (maybe all of the standard functions, shrug) for character arrays:
http://faculty.edcc.edu/~pbladek/c_string_functions.htm

STL strings have many docs, here's a useful one if you prefer code snippets, but if you like to read the actual docs, then use second link:
http://www.msoe.edu/eecs/cese/resources/stl/string.htm
http://www.sgi.com/tech/stl/basic_string.html

For any other non standard string implementations, you would have to look up the corresponding documentation yourself.
theqizmo is offline
Send a message via ICQ to theqizmo Send a message via AIM to theqizmo Send a message via MSN to theqizmo
maitredede
Senior Member
Join Date: May 2005
Old 08-03-2005 , 04:17  
Reply With Quote #3

Threads :
I'd like to add this kind of thread, so I need to know how to do, and it needs to work under windows and linux (with a few lines to change)

For the string :
I've seen string function in the sample plugin :
Code:
	if ( FStrEq( pcmd, "menu" ) )
Do you know if there is a doc with all the functions (including the one above) ? I'll search through the source files when I have time
__________________
make brain && make install
maitredede is offline
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 08-03-2005 , 08:45  
Reply With Quote #4

Quote:
Originally Posted by maitredede
Threads :
I'd like to add this kind of thread, so I need to know how to do, and it needs to work under windows and linux (with a few lines to change)

For the string :
I've seen string function in the sample plugin :
Code:
	if ( FStrEq( pcmd, "menu" ) )
Do you know if there is a doc with all the functions (including the one above) ? I'll search through the source files when I have time
The one above is nonstandard by Valve or ID or whoever, I'd prefer using functions from the C and C++ standard libraries, like strcmp, etc.

About threads: Don't forget to guard your shared data by a critical section or whatever. You could create a thread which sleeps, then checks whether there is something to do (you could maintain a list of to-do operations as a global vector or whatever), when yes, does it and stores the result somewhere, then sleeps again. In the main thread, you'd just push some info on the vector, wake up the worker thread, and then each frame check whether the result is already available. Or something like that.
__________________
hello, i am pm
PM is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:14.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode