1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Go の make の channel使ったときのデフォルト値

1
Posted at

課題

make で channel を使ったときのデフォルト値が気になった。

quit := make(chan os.Signal)

普段はキャパシティとかが後につくけど、これはどういうことだろう?デフォルト値は?

定義

こちらにこんな表があった。

Call             Type T     Result

make(T, n)       slice      slice of type T with length n and capacity n
make(T, n, m)    slice      slice of type T with length n and capacity m

make(T)          map        map of type T
make(T, n)       map        map of type T with initial space for approximately n elements

make(T)          channel    unbuffered channel of type T
make(T, n)       channel    buffered channel of type T, buffer size n

make は3つに大きくわかれているのですな。make(T) は、「バッファされない」がデフォルトのようです。
気になったのでソースコードを読んでいると、同じくコメントでありました。

// Channel: The channel's buffer is initialized with the specified
// buffer capacity. If zero, or the size is omitted, the channel is
// unbuffered.

すっきり。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?