<smart_ptr>: A newbie question (about BOOST_SP_USE_QUICK_ALLOCATOR)
Hi, I understand that shared_ptr uses the 'quick_allocator' when I compile the library with BOOST_SP_USE_QUICK_ALLOCATOR. But this means that I get the 'quick_allocator' working for every type that I use with shared_ptr, and this bothers me because this seems as a waste of memory for instances of classes that are not frequently used. Besides, the 'quick_allocator' unlike Scott Meyers suggestion (use a pool that can be destroyed) doesn't frees its free blocks which means that, shared_ptr of types that are used only in initialization stage will occupy memory which can not be recycled. Am I missing something? Thank you, Svaley --------------------------------- Yahoo! Photos Ring in the New Year with Photo Calendars. Add photos, events, holidays, whatever.
Svaley Streasm wrote:
I understand that shared_ptr uses the 'quick_allocator' when I compile the library with BOOST_SP_USE_QUICK_ALLOCATOR. But this means that I get the 'quick_allocator' working for every type that I use with shared_ptr, and this bothers me because this seems as a waste of memory for instances of classes that are not frequently used. Besides, the 'quick_allocator' unlike Scott Meyers suggestion (use a pool that can be destroyed) doesn't frees its free blocks which means that, shared_ptr of types that are used only in initialization stage will occupy memory which can not be recycled. Am I missing something?
I am quite sure that shared_ptr uses the quick_allocator only for the reference count, not for the object itself, since it doesn't allocate that. Sebastian Redl
Svaley Streasm wrote:
Hi,
I understand that shared_ptr uses the 'quick_allocator' when I compile the library with BOOST_SP_USE_QUICK_ALLOCATOR. But this means that I get the 'quick_allocator' working for every type that I use with shared_ptr, and this bothers me because this seems as a waste of memory for instances of classes that are not frequently used.
Quick_allocator uses a common heap when classes have the same size and alignment. Since shared_ptr uses quick_allocator for its control block (the class derived from sp_counted_base), and since these usually differ only by the pointer type, the typical program only uses a single heap. Of course you should use the quick_allocator only when the underlying malloc/operator new doesn't implement the small object optimization well enough, otherwise just let it do its thing. You can use shared_ptr_alloc_test to time it.
participants (3)
-
Peter Dimov
-
Sebastian Redl
-
Svaley Streasm