44 Matching Annotations
  1. Oct 2022
    1. 在新版本(起码 1.15 及以后)的 Go 当中,sync.Pool 里的临时对象需要两次 GC 才会被真正清除掉。 // 只一次 GC 的话只会让其中的临时对象被“打上记号”。 // 更具体的说,只做一次 GC 只会使得 sync.Pool 里的临时对象被移动到池中的“备用区域”(详见 victim 字段)。 // 在我们调用 sync.Pool 的 Get 方法时,如果 sync.Pool 的“本地区域”(详见 local 字段)当中没有可用的临时对象, // 那么 sync.Pool 会试图从这个“备用区域”中获取临时对象。 // 如果“备用区域”也没有可用的临时对象,sync.Pool 才会去调用 New 函数。 // 所以,这里的例子需要再添加一行对 runtime.GC() 函数的调用,才能使它的结果与最初的相同,并起到准确示范的作用。

      runtime.GC()

  2. Aug 2022
  3. Jul 2022
  4. May 2022
  5. Apr 2022
    1. 如果直接使用 DllCall 会报错,那么使用 DllLoad 先将 dll 文件加载有时就可以解决问题

      猜测难道是 golang 编译的 dll 文件太大(2-3Mb)导致DllCall 会直接导致 ahk 程序退出?

  6. Mar 2022
  7. Nov 2021
  8. Oct 2021
    1. It’s important to understand that even though a slice contains a pointer, it is itself a value. Under the covers, it is a struct value holding a pointer and a length. It is not a pointer to a struct.

      slice 是一个包含指针的结构体,他是一个具体值而不是指针

    1. 那为什么在上面的场景中,atomic会比mutex性能好很多呢?作者 Dmitry Vyukov 总结了这两者的一个区别: Mutexes do no scale. Atomic loads do. Mutex由操作系统实现,而atomic包中的原子操作则由底层硬件直接提供支持。在 CPU 实现的指令集里,有一些指令被封装进了atomic包,这些指令在执行的过程中是不允许中断(interrupt)的,因此原子操作可以在lock-free的情况下保证并发安全,并且它的性能也能做到随 CPU 个数的增多而线性扩展。

      多核场景中, atomic 性能优于 mutex 的原因

  9. Sep 2021
  10. Apr 2021
    1. Style definitions for nice terminal layouts. Built with TUIs in mind.

  11. Jan 2021
  12. Dec 2020
  13. Oct 2020
  14. Jun 2020
  15. May 2020
    1. we should never blindly apply dogmatic advice, and that we should use our judgment each and every time.

      menjadi manusia berkesedaran, memiliki pemikiran sendiri, jangan menelan mentah-mentah apa yang dibaca

  16. Apr 2020
    1. If the word “share” doesn’t come out of your mouth, you don’t need to use a pointer

      key point

    2. The benefit of passing data “by value” is readability. The value you see in the function call is what is copied and received on the other side

      no hidden cost, eg., memory growth on the heap or pauses during garbage collection. but there is a cost in stack memory usage and "scoping" among multiple stack frames, CPU caching, etc.

    3. Functions execute within the scope of frame boundaries that provide an individual memory space for each respective function. Each frame allows a function to operate within their own context and also provides flow control. A function has direct access to the memory inside its frame, through the frame pointer, but access to memory outside its frame requires indirect access. For a function to access memory outside of its frame, that memory must be shared with the function.

      eg., shared via the "pointer" to an address in heap memory

  17. Oct 2019
    1. The log will become something of a commoditized interface, with many algorithms and implementations competing to provide the best guarantees and optimal performance.

      Are golang channels an implementation of log?

  18. Aug 2019
  19. May 2019
    1. Go Programming Language publicly in 2009 they were also looking to solve certain challenges of the existing Computer languages. Of the many features that it demonstrated (we will get to those soon enough) it was also helpful in addressing the strange dilemma of hardware and software that was emerging.

      Golang is a modern computing language, designed especially for modern computing needs.

  20. Mar 2019
  21. Jan 2018
  22. Sep 2017
  23. Jul 2017
    1. (It's usually a mistake to pass back the concrete type of an error rather than error, for reasons discussed in the Go FAQ, but it's the right thing to do here because ServeHTTP is the only place that sees the value and uses its contents.)

      Good clarifying comment on when to pass back the concrete type of an error.

  24. Jan 2017
  25. Jul 2016
    1. There are two reasons for having no warnings. First, if it's worth complaining about, it's worth fixing in the code.
  26. Aug 2015