November 2019
Intermediate to advanced
404 pages
12h 9m
English
Concatenation is the act of appending strings to one another to form a larger string. As you've learned, any such cases are likely to result in excess heap allocations. The biggest offender in a string-based memory waste is concatenating strings using the + operator and += operators, because of the allocation chaining effect they cause.
For example, the following code tries to combine a group of string objects together to print some information about a combat result:
void CreateFloatingDamageText(DamageResult result) { string outputText = result.attacker.GetCharacterName() + " dealt " + result.totalDamageDealt.ToString() + " " + result.damageType.ToString() + " damage to " + result.defender.GetCharacterName() + " (" ...Read now
Unlock full access