you want to avoid too large a value as you will have 2 of those per column (levels). That could add up to a lot of unused buffer.
In DictionaryValuesWriter you could use initialSize (from the constructor) or count*bitWidth/8+header (as the upper bound you need). In that case we don't keep it around so memory overhead is less of a problem.