Subject: Re: [boost] [optional] memory use for optional refs and ptrs
From: Krzysztof Czainski (1czajnik_at_[hidden])
Date: 2010-10-05 09:54:27
2010/10/5 John Reid <j.reid_at_[hidden]>
> Rutger ter Borg wrote:
>> I'm looking into boost::optional<> as a replacement for some of my code
>> which has to deal with optional values. However, it seems that cases which
>> are usually space-efficient optionals (e.g., ptrs in the form of a null-ptr)
>> do not have template specializations. In other words, boost optional
>> templates store a bool and the memory footprint of its template parameter,
>> regardless of type. I.e., optional references and pointers take their space
>> plus the space of an extra bool.
>> Is there a reason for this?
>> Might someone want to store a null pointer in the optional? I'm not sure
> about the references though.
I understand, that a null pointer means the same as lack of a pointer.
Therefore boost::optional<> colud be specialized for pointers to take
advantage of that, and not store a bool besides the pointer in order to save
I would also like to know, if and why this space optimization is/is not
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk