'Memory use question: passing map to function vs passing only needed values from map to function

I'm teaching myself coding with kotlin and AS and as a self-assigned project I'm making a little game. I have 6 var integers that are used to get some random numbers and to modify those numbers in certain ways. In order to reduce the amount of code and to simplify passing those integers around to functions I have all 6 stored in a single mutable map. Most of the time when I pass them from one function to the other (or one class to the other) I need all 6, but there is one case where I only need 3 of them.

My question is this: Is it more efficient to pass just the 3 values I need? Or is that actually LESS efficient because I'm passing new copies of already existing values? I'm really not sure how that works internally

example: Would you...


fun main() {
    val gameArgs = mutableMapOf("numDice" to 3,
                                   "minNum" to 1,
                                  "maxNum" to 20,
                                  "modNum" to 5,
                                  "targetNum" to 17,
                                   "bonusDice" to -1,)
    
val rollNumbers = rollDice(gameArgs)
// and then send the rollNumbers and the gameArgs elsewhere to evaluate what
// the numbers mean
}

fun rollDice(args: MutableMap<String, Int>):List<Int>{
    val numList = mutableListOf<Int>()
    repeat(args["numDice"]!!){
        numList.add((args["minNum"]!!..args["maxNum"]!!).random())
    }
    return numList
}

OR, would you...


fun main() {
    val gameArgs = mutableMapOf("numDice" to 3,
                                   "minNum" to 1,
                                  "maxNum" to 20,
                                  "modNum" to 5,
                                  "targetNum" to 17,
                                   "bonusDice" to -1,)
    
val rollNumbers = rollDice(gameArgs["numDice"]!!, gameArgs["minNum"]!!, gameArgs["maxNum"]!!)
// and then send the number list and the other 3 values from the map elsewhere
}

fun rollDice(numDice: Int, minNum: Int, maxNum: Int):List<Int>{
    val numList = mutableListOf<Int>()
    repeat(numDice){
        numList.add((minNum..maxNum).random())
    }
    return numList
}

My instincts say the latter is less memory intensive, but my anxiety whispers that the latter might be MORE memory intensive because I'm making copies of 3 values that already exist.

So which is more efficient? And does it make a difference if rollDice() is in another class?

Thanks in advance

[edited to fix one type and one copy/paste error]



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source