[GSoC] Extend shared_ptr to support arrays

Tim Shen timshen@google.com
Mon Mar 16 21:21:00 GMT 2015


On Mon, Mar 16, 2015 at 12:14 PM, Fan You <youfan.noey@gmail.com> wrote:
> - Polymorphic Memory Resources
>   After reading the proposal
> <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3916.pdf>, I
> am still not quite sure about the idea of Polymorphic memory
> resources. The example on page 5 make sense to me, but what's the key
> different between the original memory allocation method and this? Any
> other resource that I can read from?

Based on my understanding, it's trying to erase the allocator from the
type information, so that user code doesn't have to care more about
types:

Is vector<int, MyAlloc> a different type from vector<int>? Can they be
assigned to each other? Can they be put into the same container? For
many case, as the proposal mentioned, they are not required to be
different, and those should be supported. This change delivers better
readability, maintainability and flexibility, with certain (I'm not
sure how much) efficiency loss: typically when doing allocation
related operations, they are virtual function calls.

It's a common thing to hide the type information by using virtual
functions. You may need to learn how vtable works (wiki page), and you
can take a look at boost::any.


-- 
Regards,
Tim Shen



More information about the Libstdc++ mailing list