3 ms·
In my Java shop, we try to write ultra-efficient code. Avoiding the creation of numerous small objects in critical sections is one of the best ways to achieve t
by alextgordon 16y ago
In my Java shop, we try to write ultra-efficient code. Avoiding the creation of numerous small objects in critical sections is one of the best ways to achieve that.
I don't know anything about Java, but the Objective-C GC recycles old allocations to avoid this exact problem. For example
for (int i = 0; i < 10000; i++)
{
Foo *foo = [[Foo alloc] init];
}
Instead of allocating memory for foo 10000 times, older allocations are kept in a pool and reused for subsequent iterations. So the actual cost of -alloc is just a memset (i.e. nothing). Java's GCs are much more mature, so I would assume they have the same optimisation.