Send different pointer structs through Channel and receive the same value

Suggestion: change QueueOutboundElement to be a class. Then don’t use pointers. A class is already a pointer-like type (it’s a reference type.)

In Go if you take a pointer/reference to something, Go is smart enough to know whether it should move that value to the heap. Crystal doesn’t work that way.

Some more suggestions:

  • Don’t use struct unless performance benchmarks show that you need it
  • Never use pointerof
  • Never use pointers

The last two are really low level things that are used to implement the basic types in the standard library, and for interfacing with C. But in general you will never use them.

4 Likes