C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

policy for dynamic array's capacity

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Antonio Xanadu
Guest





PostPosted: Fri Apr 23, 2004 11:11 pm    Post subject: policy for dynamic array's capacity Reply with quote



Hi,

IMHO, it would better if dynamic arrays e.g. std::vector
supported user-defined "capacity policy".

Examples:

struct DoubleGrow
{
// ever growing storage
size_t computeCapacity(size_t currSize, size_t newSize, size_t
currCapacity)
{ return (newSize > currCapacity) ? 2*newSize : currCapacity; }
};
struct MinGrow
{
size_t computeCapacity(size_t currSize, size_t newSize, size_t
currCapacity)
{ return (newSize > currCapacity) ? newSize : currCapacity; }
};
struct Simple
{
size_t computeCapacity(size_t currSize, size_t newSize, size_t
currCapacity)
{ return newSize; }
};
struct MoreInteresting // this one can shrink
{
size_t computeCapacity(size_t currSize, size_t newSize, size_t
currCapacity)
{
if (newSize > currCapacity || 2*newSize < currCapacity)
return newSize;
return currCapacity;
}
};
struct Stateful //has state, remembers previous usage, predicts capacity
{
size_t computeCapacity(size_t currSize, size_t newSize, size_te
currCapacity)
{
size_t result = ....; // some clever computations
return result;
}
SomeType m_stats;
};
..... // many more

typedef libxx::array Here, VEC's storage can only grow (I don't have such a guarantee with
standard
arrays)

Of course, there may exist better design for the interface of such a policy
but the fact is that quite often it is very useful to have more control on
dynamic array's capacity.

Your considerations?

AX

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.