[array] with variable size

Hello,
I have a third-party library that gives me a number N of doubles,
then expects from me a double* to an array where it will set N elements
This would have happen many times and N is variable,
so I wish not to reallocate the array each time.
I know however N is maxed at some value Nmax like 50.
I thought of using a array

On Thu, Nov 20, 2008 at 8:00 AM, Hicham Mouline
I thought of using a array
that would be allocated once, then perhaps have a wrapper around it so that only N elements of it can be accessed. This seems to be a usual idiom, are there ready implementations?
What's wrong with std::vector? You could use ::reserve to allocate memory independently of how much of it is actually being used. Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode

AMDG Hicham Mouline wrote:
I have a third-party library that gives me a number N of doubles, then expects from me a double* to an array where it will set N elements
This would have happen many times and N is variable, so I wish not to reallocate the array each time.
Can't you use a vector and resize it every time? In Christ, Steven Watanabe

It doesn't provide a pointer to the internal array that is required by my 3rd party lib...? while boost::array<> has c_array().... -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Steven Watanabe Sent: 20 November 2008 16:12 To: boost-users@lists.boost.org Subject: Re: [Boost-users] [array] with variable size AMDG Hicham Mouline wrote:
I have a third-party library that gives me a number N of doubles, then expects from me a double* to an array where it will set N elements
This would have happen many times and N is variable, so I wish not to reallocate the array each time.
Can't you use a vector and resize it every time? In Christ, Steven Watanabe _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Thank you, -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Steven Watanabe Sent: 20 November 2008 17:34 To: boost-users@lists.boost.org Subject: Re: [Boost-users] [array] with variable size AMDG Hicham Mouline wrote:
It doesn't provide a pointer to the internal array that is required by my 3rd party lib...?
Sure it does. vector<double> v; double* pDouble = &v[0]; In Christ, Steven Watanabe

Hi,
On Thu, 20 Nov 2008 17:02:04 -0000, "Hicham Mouline"
It doesn't provide a pointer to the internal array that is required by my 3rd party lib...? while boost::array<> has c_array()....
Actually you can get a pointer to the internal array. void f(double *pArray); std::vector<double> v; if (!v.empty()) { f(&v[0]); }
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Steven Watanabe Sent: 20 November 2008 16:12 To: boost-users@lists.boost.org Subject: Re: [Boost-users] [array] with variable size
AMDG
Hicham Mouline wrote:
I have a third-party library that gives me a number N of doubles, then expects from me a double* to an array where it will set N elements
This would have happen many times and N is variable, so I wish not to reallocate the array each time.
Can't you use a vector and resize it every time?
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Regards, Andy.

On Thu, 20 Nov 2008 17:00:51 +0100, Hicham Mouline
Hello,
I have a third-party library that gives me a number N of doubles, then expects from me a double* to an array where it will set N elements
This would have happen many times and N is variable, so I wish not to reallocate the array each time.
I know however N is maxed at some value Nmax like 50.
I thought of using a array
that would be allocated once, then perhaps have a wrapper around it so that only N elements of it can be accessed. This seems to be a usual idiom, are there ready implementations?
See boost_carray.zip from http://www.boostpro.com/vault/. Boris
participants (5)
-
Andy Tompkins
-
Boris
-
Emil Dotchevski
-
Hicham Mouline
-
Steven Watanabe