RE: [Dev-C++] 'extern const' and std::vector
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <iv...@at...> - 2003-05-01 15:02:42
|
-----Original Message----- From: dev...@li... [mailto:dev...@li...] On Behalf Of David = McKen Sent: Thursday, May 01, 2003 4:10 PM To: dev...@li... Subject: [Dev-C++] 'extern const' and std::vector My first question concerns the extern keyword. =20 If I have a varible in one file (it is not a constant) but that varible needs to accessed from the functions in another file. However these = other functions do not need (actually I don't want them to have) write access = to this variable, can I do something similar to 'const <var_type> = <var_name>?'. For those of you who are wondering why I don;t just try it myself I = would like to know what EVERY ANSI compatible compiler will do. The program I = am writing must remain portable. =20 =20 You do not specify language. That creates extra pain. In C & C++ yes you = can do extern const int x; In C++ you have better use a namespace. =20 My other question concerns the std::vector container class of the STD. =20 As far as I have seen the std:vector class stores it's contents = contiguously in memory (just like an array). Does this make vector classes reach = their maximum size once there is no block of memory big enough to hold it's = data?=20 =20 You haven't to worry about these details. It is an implementation worry = and in reality the vector is just a handler interface. That's why the vector::swap() works instantly. Also you can specify for it your own = memory allocator. But handlers and allocators are advanced magic for me yet so = i can't tell you more on that till i end TC++PL3. :) =20 =20 In any case you have not to worry about these details. =20 =20 =20 I plan to use this class to act as the index for world system with up = to 2^32 rooms in it (even if I store only pointers to each structure it = still gets pretty big). Would any of the other containers be better suited to = this purpose? I chose the vector bacause of it's speed (4 billion possible = rooms, gonna need the speed). The requirements for the container is to allow = for a numbering system for eah of the rooms with rooms being grouped within ranges.=20 =20 Regarding constant random access with [] time cost: vector, deque, = string, valarray and bitset have this. =20 =20 Reference for all the time costs for all containers for all types of = access ([], front operations, etc): =20 "The C++ Programming Language" 3rd Edition or Special Edition by Bjarne Stroustrup (the creator of C++): =20 On page 464. =20 =20 =20 =20 Ioannis Vranos * Programming pages: <http://www.noicys.freeurl.com/> http://www.noicys.freeurl.com * Alternative URL 1: <http://run.to/noicys> http://run.to/noicys * Alternative URL 2: <http://www.noicys.cjb.net/> = http://www.noicys.cjb.net Anti-racism movement: <http://www.positive-youthfoundation.org/> http://www.positive-youthfoundation.org Iraq Peace Pledge: <http://www.peacepledge.org/> = http://www.peacepledge.org =20 |