Skip to content

Instantly share code, notes, and snippets.

@earayu
earayu / dairy.md
Last active February 19, 2024 11:50
We couldn’t find that file to show.

考虑这个问题: 在Golang的函数中创建一个struct,然后将它return,这个struct的内存空间会被分配在哪里?return的时候会有哪些操作?是否会发生拷贝?

有关go内存是在堆上分配的,还是在栈上分配的,这个是在编译过程中,通过逃逸分析来确定的,其主体思想是: 假设有变量v,及指向v的指针p,如果p的生命周期大于v的生命周期,则v的内存要在堆上分配。 https://cloud.tencent.com/developer/article/1861199

小技巧:我们也可以在编译时,通过加上-m参数,来让编译器告诉我们,一个变量到底是分配在堆上,还是在栈上

@earayu
earayu / TodoListTemplate.md
Last active April 23, 2023 11:01
Todo list template

Template:

- [x] task1
- [ ] task2
- [x] task3
- [ ] task4

Effect:

  • task1
  • task2