Re: A Better Choice?
On 9/28/2013 6:15 PM, Mike Copeland wrote:
I have the following data declaration that is causing compiler
warnings:
char DBI[60001] = {'\0'} ;
If that's inside a function (automatic storage duration), it's a lot of
chars to allocate on the stack...
The purpose of this data is to store a character value ('a'..'I') for
each corresponding record that has been read from a database. The
records are identified by a value that ranges from 1-60000. I can't use
a bitset here, as I need to store the character value associated with
each record. I don't want to be limited by the current supported range
(1...60000).
I'm looking for a better (STL container?) technique that might serve
my purpose but also avoid the fixed size constant declaration which is
causing compiler warnings. Also, I'm not especially concerned with
performance in this functionality. Any thoughts? TIA
You can do anything you want, but the easiest, I think, is to use a
vector of chars of a fixed length given at the initialization:
std::vector<char> DBI(60001, '\0');
The difference from what you have is that it will use free store to
allocate the elements, and it will free that memory afterwards, so you
don't need to pay much attention to it.
If you need more elements in the same vector later, you can make the
vector grow by mean of 'resize' function or by simply pushing new values
at the end, which will cause it to resize itself.
V
--
I do not respond to top-posted replies, please don't ask