Cost of passing references as input parameters

Hello,

Quick question regarding the cost of using references to identify player controllers in multiplayer games.

Let’s say I want to execute an event for a specific player or to send data to the server from the client. How I would currently do it: every PC has a unique ID associated, and I pass this integer as input for the events. Is it really a better practice as just passing the controller pointer?

Another example: if I’ve got a map variable to store the score of every player, to what extent is it better to use Key: int32 PC_Id and Value: int32 Score than Key: APlayerController PC and Value: int32 Score?

Quick answer: Use whatever is most convenient for you and is easiest to understand.

Referencing and de-referencing pointers (references) compute cost is negligible. A single vector normalization is usually several (tens or hundreds) times slower.

In terms of size I think reference size is 64bit on an x64 machine which is twice an int32 size.

If you are coding for a watch (or something with incredibly tight memory budget) don’t use UE in first place. In all other cases the memory footprint of your player array will be negligible. A single 4k texture will probably be larger than all your game-play structures and data.

1 Like