Jump to content
  • Advertisement
Sign in to follow this  

threading and shared data class

This topic is 3740 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I think there's a bug in the forum software that sometimes causes posts with certain code snippets to not display.

Try copying your code to a pastebin site (like this one) and posting a link to it here instead.

Share this post

Link to post
Share on other sites
EDIT: that was weird... thx for the tip

ive made a simple system baed on the producer/consumer pattern for my engine...

basicly i have 2 thread one update thread(producer) and a render thread(consumer)... the basic idea is to keep two mirrored copies of all data for each thread... so if the update thread updates an object the class makes a copy of the modified object and sends it over to the render thread...

its not very advanced and i think its pretty much self explanatory


my question is how i can make this faster?

the problem im specifically thinking about is that the objects are "memcpy"id twice which is unecssary... it would be better if the consumer could simply switch pointers with the objectpool...

|¤| = state data
|#| = change data
| | = reusable memory


STEP 1: send data to consumer (copy to a memory pool)

-> |#| -> |#| ->
producer|¤| |¤| consumer

STEP 2: switch pointers (right now im simply copying again)

-> |#| ->
producer|¤| |#| <-> |¤| consumer

STEP 2: recycle data

|#| -> |#| ->
producer|¤| |¤| consumer
<- | | <-

it would probably only be possible if i switched pointer for the chunks.. this requires however that the entire chunk is copied in the producer which is alright even if not all objects are modified since memcpy on the entire chunk would be faster than copying objects one by one... and i can only tweak the chunk size depending on how likely it is that the data will be changed and has to be copied..

im unsure how i would implement this properly or if its even a good idea... any help or suggestions?

EDIT: switch placed between producer and consumer...

[Edited by - Dragon_Strike on August 16, 2008 2:47:02 PM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!