On Mon, Aug 11, 2025 at 9:05 AM Haddock <bienlein1...@gmail.com> wrote:
>
> in Go there are no functions on built-in types like int, float, string. Let's 
> say I do something like this to have a type mystring that has a function 
> ToUpper:
>
> type mystring string
>
>  func (self *mystring) ToUpper() mystring {
>
>                 return mystring(strings.ToUpper(string(*self)))
>
> }
>
> I'm new to Go, have little understanding and knowledge about it. So I'd like 
> to ask what the cost is in that kind of helper functions and the involved 
> conversions on things like memory load, added CPU time, etc.

The conversion from "string" to "mystring" has no run time cost. In
general, if you have "type T1 T2", then a conversion between "T1" and
"T2" has no run time cost.

Conversions between different types, such as "string" to "[]byte", can
have a run time cost.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcV%3DKSBL7Rx2-TWS_2xwo3DW7ypvEOq46GUzbnnGU-Or%3Dw%40mail.gmail.com.

Reply via email to