Okay, thanks for replying.
I don't still get the full gist of this but I guess you will need to fiddle with the actual code to get a total understanding.
Solo miners (or mining pools) get to choose the size of their blocks as long as it is equal to or smaller than the consensus rule on maximum block size. Currently the consensus rule is that blocks cannot be larger than 1 megabyte, but there are several discussions occurring about changing that maximum limit in the future.
The most profitable thing to do would be to fill the block right up to the limit with the transactions that pay the largest amount PER BYTE. If the solo miner (or mining pool) isn't aware of enough transactions to fill the block, then the most profitable thing to do is to include all transactions that pay any fee at all. Including free transactions is up to the generosity of the solo miner (or pool) since it does not increase their revenue at all (and each byte added to the block very slightly increases the odds that the block may become orphaned).
As such, if there is a backlog of more than enough fee-paying transactions, then the blocksize will be any size less than or equal to the consensus limit that the solo miner (or mining pool) chooses it to be. In most cases this is likely to either be very close to the consensus limit or very close to any limit the miner (or pool) has personally chosen. It is likely to only change by a few hundred bytes or so as the miner (or pool) replaces transactions that pay a lower fee-per-byte with transactions that pay a higher fee-per-byte as the miner (or pool) hears about them).
If there is not a backlog of fee-paying transactions, then the solo miner (or mining pool) may choose to add new fee-paying transactions to their blocks as they hear about the transactions in order to increase the revenue that the block will generate for them.