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 <jlforr...@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
> <https://groups.google.com/d/msgid/golang-nuts/b6555128-1a87-486c-8771-647d862756c7n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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.

Reply via email to