Boost logo

Boost :

From: Greg Colvin (gcolvin_at_[hidden])
Date: 2000-12-12 21:57:04


What's wrong with std::vector?

----- Original Message -----
From: "David Abrahams" <abrahams_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Tuesday, December 12, 2000 6:51 PM
Subject: Re: [boost] shared_array.size()

Joe,

you use shared_array the same way you'd use the result of new int[10], e.g.
in code where you know the expected size of the array but don't wish to copy
the array contents upon return from a function. I can understand the utility
of your suggestion, but I think maybe it makes sense to have another layer
(what to call it, though?) which can be used as follows:

    boost::shared_array2<int> x(10); // allocate 10 ints
    std::size_t length = x.size();

Regards,
Dave
----- Original Message -----
From: "Joe Gottman" <joegottman_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Tuesday, December 12, 2000 8:57 PM
Subject: Re: [boost] shared_array.size()

That's why I said the constructor and the reset would need an extra
parameter, so that the user could include the size. Thus, instead of
boost::shard_array<int> my_array(new int [10]);

we would have

boost::shared_array<int> my_array(new int[10], 10);

Currently, there is no safe way to get a shared_array as a return value of a
function. If you have code like

boost::shared_array<int> my_array = foo();

how could you subsequently use my_array? Without knowing the size of
my_array, you cannot safely call my_array[10], because there might only be 5
elements.

Joe Gottman
  ----- Original Message -----
  From: Schaible, Joerg
  To: boost_at_[hidden]
  Sent: Tuesday, December 12, 2000 7:19 AM
  Subject: AW: [boost] shared_array.size()

  Hi Joe,

  this is not in the scope of this class. Since you cannot request the size
from an array you've allocated dynamically, the shared_array cannot report
either.

  Greetings,
  Jörg

  -----Ursprüngliche Nachricht-----
  Von: Joe Gottman [mailto:joegottman_at_[hidden]]
  Gesendet: Dienstag, 12. Dezember 2000 02:51
  An: boost_at_[hidden]
  Betreff: [boost] shared_array.size()

      I have been using the shared_ptr from "smart_ptr.hpp" and have found
it very useful. However, I am afraid to try using the shared_array from the
same file. The problem is that shared_array does not have a size() member
function. This makes it very dangerous to use the shared_array if the user
doesn't know what size array it was created with, for instance if it was
returned from a function.

     I think the shared_array would be much more useful with a size()
member. However, this would necessitate changing the constructor and the
reset() function to take an extra parameter to indicate the size. Also, it
would necessitate using a third pointer to store the size.

  Joe Gottman


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