-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi! Am 19.03.12 17:28, schrieb Szymon Gatner:
This way you get 2 heap allocations + shared_ptr<> construction as opposed to just internal allocation of vector (using allocator). This is especially bad if returned vector turns out to be empty. In that case vector might not do allocation at all so vector creation and return are practically free.
The shared_ptr construction means what? The vector will allocate and the boost::make_shared allocates memory on the heap. The copying of the shared_ptr is rather cheap in comparison. One use case: distribute any number of subranges of a shared range. Imagine a function that returns (by value) a list (or vector) of substrings (shared_iterator pairs = ranges) of some larger string. The substrings can shared ownership on the underlying large string. Of course there are alternatives to shared iterators, but its a valid use case anyway, I think. Frank -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.17 (Darwin) Comment: GPGTools - http://gpgtools.org Comment: keyserver x-hkp://pool.sks-keyservers.net iEYEARECAAYFAk9nrsoACgkQhAOUmAZhnmp1igCeP7UeAho8Hc1Q8iQy4x/LOXu9 FYEAnRtyEGOqhEfnRrXWkFG4D3HOsmyY =bodr -----END PGP SIGNATURE-----