Ticket #943 (new enhancement)

Opened 7 years ago

Last modified 7 years ago

Avoid two lots of allocations for new ClassUsingPimp

Reported by: ciaranm Owned by:
Priority: Sometime Milestone:
Component: core/paludis/util Version: scm
Keywords: Cc:
Blocked By: Blocking:
Distribution: N/A

Description

It's probably possible...

Attachments

0001-Use-in-class-storage-allocation-optimization.patch Download (5.6 KB) - added by prak 7 years ago.
Quick hack, adjusted just paludis/util directory, reset is implementable too.

Change History

comment:1 Changed 7 years ago by ciaranm

Might be tricky, since we usually allocate using std::make_shared, which uses placement new.

comment:2 Changed 7 years ago by prak

How about using pool allocator and allocate_shared. I had some toy implementation of your Pimpl ptr extended, to use allocators (with EBO), but never used it in real code. Btw. scoped_allocator_adapter in libstdc++ is on its way too. I'll cleanup my patches once I'll get FSF copyright assignment. Another idea is to use some aligned storage, and allocate there if size/alignment fits (like libstdc++ versa string does atm). 2nd could be superior solution.

comment:3 Changed 7 years ago by ciaranm

I didn't think pool allocators made any difference in the real world. What I'm really trying to avoid here is having three allocations for most objects. There's the reference count for the shared_ptr, the class and the imp. std::make_shared is supposed to combine the first two. I'm wondering whether we can get the imp as part of that too.

comment:4 Changed 7 years ago by prak

I'll take a closer look at that. I think it is possible. But just wonder, are all those types really need value semantic, I tuned recently some code using pimpl, just by changing imp ptr to unique_ptr, and gaved types move construcible semantic.

comment:5 Changed 7 years ago by ciaranm

unique_ptr gets const wrong. And there's no particular need for Imps to be copyable, other than that new X{a...} breaks gcc 4.4.

Changed 7 years ago by prak

Quick hack, adjusted just paludis/util directory, reset is implementable too.

comment:6 Changed 7 years ago by prak

It is possible add traits for storage size for case by case fine-tuning, but, thats probably hard work, and will need be keep up to date.. so not really perfect solution. This size is picked to avoid additional allocation in whole util directory (x86-32).

Note: See TracTickets for help on using tickets.