To be very exact, this case would actually cause a fault, and is a good
example of why manual management here is best not allowed:
```go
func loop(someSlice []int) {
for _, x := range someSlice {
use(x)
markDelete(x)
}
}
```
Even though you specified for x := range ..., inside the for loop, x is
reused. It gets allocated once, when we enter the for loop and reused (with
just another value assigned) as we iterate through it. Got me by surprise
since it's := and I was trying to use its pointer &x to find I was reusing
the same pointer.
On Friday, May 28, 2021 at 8:48:01 AM UTC+1 [email protected] wrote:
> yes, i immediately got the point(it is far different from golang ) after i
> type these words.
> so sorry to disturb
>
> On Friday, May 28, 2021 at 3:39:25 PM UTC+8 Jesse McNelis wrote:
>
>> On Fri, May 28, 2021 at 4:51 PM cheng dong <[email protected]> wrote:
>>
>>> Thank you for the clarification.
>>> sorry to break the general rule, i'm new to golang-nuts
>>>
>>> as to the question, i figured out i used wrong words, what i need in
>>> fact is1. a hint to tell compiler that some object are safe to alloc on
>>> stack(in case that we use it as interface so it escape from stack) 2. some
>>> concept like unique ptr that when it end it's life time, the object
>>> referenced can be deallocated immediately.
>>>
>>
>> For Go to be memory safe the compiler can't trust your hint because you
>> could be wrong either by a mistake or by changes to future code
>> invalidating some assumption you had.
>> A feature like Rust's unique pointers (and thus also borrowing and
>> lifetimes) would require large changes to the language and completely
>> change what Go is.
>>
>> If you want the features of Rust then use Rust.
>>
>>
>>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/450a2f92-7e3a-45ac-94a7-e344f1bbad25n%40googlegroups.com.