3 ms·
in go you can do this with a channel of ununused structs if pulling from the channel hits default branch of select, make a new one. same if adding back to the
by lanstin 3y ago
in go you can do this with a channel of ununused structs if pulling from the channel hits default branch of select, make a new one. same if adding back to the channel hits default, then free it; else just stick them in the channel and pull them off. eases GC pressure in hot paths. does put a little scheduler pressure.
- vore 3y agoWhy not just do this with a regular stack and avoid having to deal with the scheduler at all? Try pop from the stack and if the stack is empty, do a new allocation.
- lanstin 3y agoBecause I am using them in different go routines and I find Go channels are pretty good at handling the synchronization as well as I can.