Grokking Advanced Go
0% completed
Reducing Allocations
A receipt for an order with eight items is 184 bytes long. The function below needs 34 heap allocations and 1,384 bytes of memory to build it, which is more than seven times the size of the result.
One possible output (a normal build):
allocations per receipt: 34 bytes per receipt: 1384 receipt length: 184
At 1,000 receipts per second, this function makes 34,000 allocations totaling about 1.4 MB every second. That may be a real cost or a negligible one, depending on what else the program does. Only a measurement shows which.
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%