Boost logo

Boost :

From: David B. Held (dheld_at_[hidden])
Date: 2003-10-06 13:48:29


"E. Gladyshev" <egladysh_at_[hidden]> wrote in message
news:20031006174044.25745.qmail_at_web40803.mail.yahoo.com...
> [...]
> If I say:
>
> struct my_type
> {
> ...
> };
>
> typedef boost::variant< my_type > my_v;
> std::vector< my_v, my_allocator<my_v> > v;
>
> f()
> {
> my_type t;
> v.push_back( t );
> }
>
> How does the my_type variable gets allocated when it is
> transferred to the variant?

If variant doesn't use dynamic allocation, I assume that means
that the my_types are stored directly in v, but wrapped in the
variant. So when push_back() is called, if it needs to resize
the vector, it asks the allocator for a larger chunk of my_v's.
If not, it just copies into the existing reserved space. At
some point, a variant would get c'ted from t, and copied
into that array. No per-variant heap allocation required.

Dave

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.521 / Virus Database: 319 - Release Date: 9/23/2003

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk