Go Built-In Function new: Difference between revisions
Jump to navigation
Jump to search
Line 3: | Line 3: | ||
=Overview= | =Overview= | ||
<code>new()</code> can be used to create new | <code>new()</code> can be used to create [[Go_Structs#new|new struct instances]]. | ||
=TO DEPLETE= | =TO DEPLETE= | ||
<font color=darkkhaki> | <font color=darkkhaki> |
Revision as of 01:23, 25 August 2023
Internal
Overview
new()
can be used to create new struct instances.
TO DEPLETE
Internal
Overview
The new() built-in function takes a type as argument, allocates memory of the given type and returns a pointer to it.
var ptr *some_type ptr = new(some_type)
We don't have to worry about de-allocating memory allocated with new(). It is automatically garbage collected.
new() and New()
The "errors" package exposes a New() function. Do not mistake it for new().