Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 29 Mar 2012
Offline Last Active Today, 07:35 AM

Posts I've Made

In Topic: Use Of Static Variables

04 August 2016 - 05:06 AM

Statics are fine for singletons like a factory class or something, but i tend not to use them for variables at all -> There are always an entry point in every application!

When i find me in a situation when i pass too much parameters to a method i just use a "context pattern" and wrap this parameters into its own class/struct and pass this instead.

Example: UpdateGame(GameState *state) against UpdateGame(RenderState *renderState, MemoryState *Memory, InputState *state, ...)


But i use statics for method declarations all the time, because static has more meanings that just "global". Static in c++ can mean also "internal" - like "can be used in this unit only.

The first thing i do in C to declare a macros like this and use this instead of static directly (filtering is much easier this way):


#define internal_method static

#define global_variable static

#define local_persist static


Statics are also bad in other scenarios, like for example:


- Statics in a Server application (Except from factory instances) are bad when the scope/thread switches (Reloading a dll or something can cause this!)

- Multithreading/Parallel computation can go very wild with statics even with proper locking mechanism (GC decides to dispose static or something - will not happen in C...)

- Compiler may do nasty optimizations on static variables which may cause unforeseen consequences now or in the future

In Topic: Unreal Engine 4 Velocity From Distance + Gravity

24 July 2016 - 05:33 AM

Found a solution from https://forums.unrealengine.com/showthread.php?58157-TUTORIAL-BP-Jump-Pad-only-adjust-Destination-Point-Not-Beginner-friendly-atm

Works perfectly fine ;-)

In Topic: Single producer - multiple consumer fast queue?

21 June 2016 - 11:09 PM

Can't the queue just contain pointers to these large 300kb packets?


Then you can use a fast SPMC queue of pointers, and separately, a lock-free pool allocator of the packets themselves.


Oh this may work, i will give it a try.

In Topic: Single producer - multiple consumer fast queue?

21 June 2016 - 12:55 PM

How much memory do you need to copy? Because you would have to literally be copying several GB worth of data per second to show up as a problem. Unless this is the case, it sounds to me you're hitting false cache sharing issues while doing the copy, which would slowdown all cores considerably.


Hmm after analyzing, it happens to be around ~300 kb at max for a packet. So you are basically right - there is too much going on. Back to the drawing board.

In Topic: Single producer - multiple consumer fast queue?

21 June 2016 - 10:28 AM

First step: Write a lock based one, or better yet, use an existing queue such as ConcurrentQueue, which is already moderately lock free (source).
Second step: If profiling actually shows it to be a problem, then invest the time to replace it.


As for writing a lock free circular queue goes, for starters: Time consuming operations should be completed long before you ever attempt to insert the object into the queue. Your insertion into the queue should be one or more CAS operations based on the result of the CAS.


The queue itself is not the problem, but the fixed memory used for the queue entries and the process of copy the memory into the slot.

Adding or removing from the queue works just fine. Seems i need another lock for each entry to solve this problem - so a decoder can dequeue but waits until the memory is finished.