The operators
and new()
are expensive. delete()
When we talk about a method or an approach being expensive, we mean that this method uses a lot of resources, such as memory or CPU cycles. Using
and new()
is expensive because they have a lot of overhead, and allocating memory does not happen quickly.delete()
It is sometimes more efficient to grab a large area from
and manage it yourself. Doing so cuts down on the number of times that new()
and new()
are called. You grab a large area, and you don't call delete()
again until you use it up. If you use it up quickly you may want to grab twice as much next time.new()
Managing this pool of objects takes some overhead as well, however. You will have to decide if the cost of managing the pool of memory is greater than the cost of repeatedly calling
. Generally, if you are creating a lot of objects, they are all of the same size and performance is critical, then this may be worth doing.new()