Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is considered a small object in C++?

I've read about Small-Object Allocation in "Modern C++ Design". Andrei Alexandrescu argues that the general purpose operators (new and delete) perform badly for allocating small objects.

In my program there are lot of objects created and destroyed on the free store. These objects measure more than 8000 bytes.

What size is considered small? Are 8000 bytes small or big when it comes to memory allocation in C++?

like image 892
Jan Deinhard Avatar asked Aug 08 '10 19:08

Jan Deinhard


1 Answers

The definition of "small" varies, but generally speaking, an object can be considered "small" if its size is smaller than the size overhead caused by heap allocation (or is at least close to that size).

So, a 16 byte object would probably be considered "small" in most cases. A 32 byte object might be considered small under certain specific circumstances. An 8,000 byte object is definitely not "small."

Usually, if you are going to go through the trouble of using a small object allocator, you are looking to improve the performance of some block of code. If using a small object allocator doesn't help your performance, you probably shouldn't use one.

like image 64
James McNellis Avatar answered Sep 24 '22 14:09

James McNellis