Are the variables passed to "html/template" passed by reference, by value, or by the original type of the variable?

I understand that maps in Go are passed by reference, but what happens if a 1GB map is a variable to execute a template with “html/template”?

Will another 1GB copy be made in memory before executing it in the template? or will it be passed by reference?

but what happens if a 1GB map is a variable to execute a template with “html/template”?

I don’t quite understand this sentence. But, I assume what you meant is you pass the map as the map to Execute function. In that case, it will be passed by reference, no copy needed.

Yes, I was referring to the Execute function. Thanks for the information.

Here are a few interesting articles:

So technically, the idea of a reference might be incorrect but nonetheless, no copy of the underlying data is made.

1 Like

Good articles there. Yes, there is no reference in Golang. What we thought as pass-by-reference is actually pass-by-value, but the value is pointer. This is true for other languages like javascript, java, python, etc. I only know reference in C++ and Rust.

1 Like