本文介绍了什么是C ++中的小对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了现代C ++设计"中的小对象分配. Andrei Alexandrescu认为,通用运算符(new和delete)在分配小对象方面表现不佳.

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.

在我的程序中,免费商店中创建和销毁了很多对象.这些对象的大小超过8000个字节.

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

什么尺寸才算小?在C ++中分配内存时,是8000个字节是大还是小?

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

推荐答案

"small"的定义各不相同,但通常来说,如果对象的大小小于堆分配所导致的大小开销,则可以将其视为"small" (或至少接近该尺寸).

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).

因此,在大多数情况下,一个16字节的对象可能会被认为是小"的.在某些特定情况下,一个32字节的对象可能被认为很小. 8,000个字节的对象绝对不是小".

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.

这篇关于什么是C ++中的小对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 07:50