[go-nuts] Re: Confused about heap usage for empty slices

2022-09-07 Thread 'Keith Randall' via golang-nuts
(Actually, that address is an address on the stack, but that's only because 
the backing store for emptySlice does not escape. It should also take ~no 
space.)

On Wednesday, September 7, 2022 at 4:53:12 PM UTC-7 Keith Randall wrote:

> That address is not in the heap. It is the address of a special word in 
> the runtime, called runtime.zerobase, which is explicitly for this purpose. 
> It is a place to point things that need to be non-nil but have no size.
>
> On Wednesday, September 7, 2022 at 12:01:28 PM UTC-7 me...@pobox.com 
> wrote:
>
>> Running this:
>>
>> emptyslice := []string{}
>> sh := (*reflect.SliceHeader)(unsafe.Pointer())
>> fmt.Printf("empty slice cap = %d\n", sh.Cap)
>> fmt.Printf("empty slice len = %d\n", sh.Len)
>> fmt.Printf("empty slice uintptr = %v\n", sh.Data)
>>
>> Output:
>>
>> empty slice cap = 0
>> empty slice len = 0
>> empty slice uintptr = 824634224152
>>
>> The non-zero uintptr suggests that something is allocated on the heap. 
>> But the cap is 0, so any backing array should have a size of 0. So what is 
>> allocated on the heap? Surely not an array of size 0?
>>
>>
>> mathew
>>
>

-- 
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 on the web visit 
https://groups.google.com/d/msgid/golang-nuts/aad4acd3-500f-4d2e-9911-07307d4bcc9dn%40googlegroups.com.


[go-nuts] Re: Confused about heap usage for empty slices

2022-09-07 Thread 'Keith Randall' via golang-nuts
That address is not in the heap. It is the address of a special word in the 
runtime, called runtime.zerobase, which is explicitly for this purpose. It 
is a place to point things that need to be non-nil but have no size.

On Wednesday, September 7, 2022 at 12:01:28 PM UTC-7 me...@pobox.com wrote:

> Running this:
>
> emptyslice := []string{}
> sh := (*reflect.SliceHeader)(unsafe.Pointer())
> fmt.Printf("empty slice cap = %d\n", sh.Cap)
> fmt.Printf("empty slice len = %d\n", sh.Len)
> fmt.Printf("empty slice uintptr = %v\n", sh.Data)
>
> Output:
>
> empty slice cap = 0
> empty slice len = 0
> empty slice uintptr = 824634224152
>
> The non-zero uintptr suggests that something is allocated on the heap. But 
> the cap is 0, so any backing array should have a size of 0. So what is 
> allocated on the heap? Surely not an array of size 0?
>
>
> mathew
>

-- 
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 on the web visit 
https://groups.google.com/d/msgid/golang-nuts/8adabc71-f706-4638-8e17-8f3876b9abadn%40googlegroups.com.


[go-nuts] Confused about heap usage for empty slices

2022-09-07 Thread mathew murphy
Running this:

emptyslice := []string{}
sh := (*reflect.SliceHeader)(unsafe.Pointer())
fmt.Printf("empty slice cap = %d\n", sh.Cap)
fmt.Printf("empty slice len = %d\n", sh.Len)
fmt.Printf("empty slice uintptr = %v\n", sh.Data)

Output:

empty slice cap = 0
empty slice len = 0
empty slice uintptr = 824634224152

The non-zero uintptr suggests that something is allocated on the heap. But 
the cap is 0, so any backing array should have a size of 0. So what is 
allocated on the heap? Surely not an array of size 0?


mathew

-- 
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 on the web visit 
https://groups.google.com/d/msgid/golang-nuts/281f51c3-b94f-4b13-9d80-7b0236d8dbfan%40googlegroups.com.


Re: [go-nuts] Assigning struct values

2022-09-07 Thread burak serdar
On Wed, Sep 7, 2022 at 12:28 PM Mustafa Durukan 
wrote:

>
>
> *fakeObject := tt.Object.(TypeOfStruct)object := Object.(TypeOfStruct)*


If you can include the definitions of tt, explain what you want to do, and
what you mean by "didn't  work", someone may be able to answer this
question. Without those, it is not clear what you are trying to achieve.


>
>
> *fakeObject.Field = object.FieldfakeObject.Field2 = object.Field2*
>
> I have case like that.
> I want to assign sme object values to tt.Object but when i try to assign
> it assings to fakeObject i mean copy of tt.Object so I cant assign
>
> I tried these assigns
>
> *tt.Object.(TypeOfStruct).Field =
> object.Fieldtt.Object.(TypeOfStruct).Field2 = object.Field2*
>
> or
>
>
>
> *tt.Object:= tt.Object.(TypeOfStruct)tt.Object.Field =
> object.Fieldtt.Object.Field2 = object.Field2*
>
> But both of them didnt work
> How should i achieve it?
> btw tt.Object and Object are interface{} of course
>
> --
> 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 on the web visit
> https://groups.google.com/d/msgid/golang-nuts/d1539b71-8344-4199-bb7c-ef95b3cf2badn%40googlegroups.com
> 
> .
>

-- 
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 on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAMV2RqqvuMR1ftKz1yE%2BdE9WJ5g-512gc5sVRew9gkX0K_ri%2Bg%40mail.gmail.com.


[go-nuts] Assigning struct values

2022-09-07 Thread Mustafa Durukan




*fakeObject := tt.Object.(TypeOfStruct)object := 
Object.(TypeOfStruct)fakeObject.Field = object.FieldfakeObject.Field2 = 
object.Field2*

I have case like that.
I want to assign sme object values to tt.Object but when i try to assign it 
assings to fakeObject i mean copy of tt.Object so I cant assign

I tried these assigns

*tt.Object.(TypeOfStruct).Field = 
object.Fieldtt.Object.(TypeOfStruct).Field2 = object.Field2*

or



*tt.Object:= tt.Object.(TypeOfStruct)tt.Object.Field = 
object.Fieldtt.Object.Field2 = object.Field2*

But both of them didnt work 
How should i achieve it?
btw tt.Object and Object are interface{} of course

-- 
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 on the web visit 
https://groups.google.com/d/msgid/golang-nuts/d1539b71-8344-4199-bb7c-ef95b3cf2badn%40googlegroups.com.