Re: [go-nuts] Two Questions About Maps

2021-12-19 Thread jlfo...@berkeley.edu


On Sunday, December 19, 2021 at 9:24:00 AM UTC-8 Jan Mercl wrote:

> On Sun, Dec 19, 2021 at 6:03 PM jlfo...@berkeley.edu 
>  wrote: 
> > 1) Let's say I wanted to make the map elements smaller, so the map value 
> would be a pointer to a structure, not the structure itself. I couldn't 
> figure out how to modify this program so that the initialization still 
> worked. Any ideas? 
>
> Here's one: https://go.dev/play/p/ycp3dX9BzRn


Thanks! I had thought of that but couldn't figure out how to modify the 
initialization to yield a pointer to the structure. I didn't realize that 
it wasn't necessary, and that the compiler does it automatically.

Jon



-- 
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/31204943-f73d-482d-b8da-9966401ad70an%40googlegroups.com.


Re: [go-nuts] Two Questions About Maps

2021-12-19 Thread Brian Candler
Oops, please ignore that.  I was modifying the wrong play code.

>

-- 
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/6ab11f1b-4ed7-4cae-9fa7-e7a1cb28b219n%40googlegroups.com.


Re: [go-nuts] Two Questions About Maps

2021-12-19 Thread Brian Candler
On Sunday, 19 December 2021 at 17:24:48 UTC b...@gmail.com wrote:

> you must use pointers, otherwise you can not do something like this:
>
> ft["a"].name = "b" 
>
> As the entries in the map are non-addressable.
>

???

https://go.dev/play/p/ubx-WnElJOY

-- 
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/d66f5092-e3fd-427d-9b11-9c4560c87042n%40googlegroups.com.


Re: [go-nuts] Two Questions About Maps

2021-12-19 Thread Bruno Albuquerque
https://go.dev/play/p/fglmNnWFUxP

I would not worry about using pointers inside the map if the data is really
read only. If it is not, you must use pointers, otherwise you can not do
something like this:

ft["a"].name = "b"

As the entries in the map are non-addressable.


On Sun, Dec 19, 2021 at 9:03 AM jlfo...@berkeley.edu 
wrote:

> Consider the following extremely condensed program:
>
> package main
>
> type func_type func (a string)(out int)
>
> type fte struct {
> name string
> expand_args  bool
> function func_type
> }
>
> var ft = map[string]fte {
>   "a":{"a", true, func_a},
> };
>
> func func_a(a string) int {
> return 1
> }
>
> func main() {
> }
>
> It works fine, but it made me wonder two things.
>
> 1) Let's say I wanted to make the map elements smaller, so the map value
> would be a pointer to a structure, not the structure itself. I couldn't
> figure out how to modify this program so that the initialization still
> worked. Any ideas?
>
> 2) Is it even worth worrying about the size of map values, especially in
> maps that don't change during runtime? In the real program this example
> came from, the "fte" structure is much larger, and there could be many more
> elements in the map. Using a pointer as the value would make the map
> smaller but ultimately the amount of memory used wouldn't change because
> the pointers would have to point to structures outside the map.
>
> Thanks for any advice,
> Jon Forrest
>
> --
> 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/b6555128-1a87-486c-8771-647d862756c7n%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/CAEd86TwPA5%2BFLkjV2B9AxR8QSKSdnDtC_dHKopEy%2BWZ2_Y%3D9iQ%40mail.gmail.com.


Re: [go-nuts] Two Questions About Maps

2021-12-19 Thread Jan Mercl
On Sun, Dec 19, 2021 at 6:03 PM jlfo...@berkeley.edu
 wrote:
> 1) Let's say I wanted to make the map elements smaller, so the map value 
> would be a pointer to a structure, not the structure itself. I couldn't 
> figure out how to modify this program so that the initialization still 
> worked. Any ideas?

Here's one: https://go.dev/play/p/ycp3dX9BzRn

> 2) Is it even worth worrying about the size of map values, especially in maps 
> that don't change during runtime? In the real program this example came from, 
> the "fte" structure is much larger, and there could be many more elements in 
> the map. Using a pointer as the value would make the map smaller but 
> ultimately the amount of memory used wouldn't change because the pointers 
> would have to point to structures outside the map.

Using pointers vs values from the performance POV is often a
difference that can be decided only by measurement. To make things
more complicated, the measurements tend to differ across different HW,
sometimes in a contradictory manner.

The only obvious case is passing around _very_ large values. There
using a pointer instead will always perform better. But many values
are not big enough to make a clear cut.

-- 
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/CAA40n-XCX9RoDmHJEPNUsvfavbLqU0qjx_Tw6-c7vgvjh0taZA%40mail.gmail.com.


[go-nuts] Two Questions About Maps

2021-12-19 Thread jlfo...@berkeley.edu
Consider the following extremely condensed program:

package main

type func_type func (a string)(out int)

type fte struct {
name string
expand_args  bool
function func_type
}

var ft = map[string]fte {
  "a":{"a", true, func_a},
};

func func_a(a string) int {
return 1
}

func main() {
}

It works fine, but it made me wonder two things.

1) Let's say I wanted to make the map elements smaller, so the map value 
would be a pointer to a structure, not the structure itself. I couldn't 
figure out how to modify this program so that the initialization still 
worked. Any ideas?

2) Is it even worth worrying about the size of map values, especially in 
maps that don't change during runtime? In the real program this example 
came from, the "fte" structure is much larger, and there could be many more 
elements in the map. Using a pointer as the value would make the map 
smaller but ultimately the amount of memory used wouldn't change because 
the pointers would have to point to structures outside the map.

Thanks for any advice,
Jon Forrest

-- 
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/b6555128-1a87-486c-8771-647d862756c7n%40googlegroups.com.


[go-nuts] Generic symbol name in binary

2021-12-19 Thread 'Dmitry Neverov' via golang-nuts
Is the naming scheme for generic symbols in binaries described somewhere? 

Thanks!

-- 
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/9a6dd6d5-0e50-4076-a86f-be5c5cb10e86n%40googlegroups.com.