Re: [Dev-C++] 'extern const' and std::vector
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: David M. <ci...@ya...> - 2003-05-01 15:21:45
|
MessageI think I better explain my current position. I am helping create a MMORPG. The vector is going to be used for access to the rooms. The current room system uses vnums (each rooms is assigned a vnum which is used to access it, another reason for my choice of vector). exits to other rooms just refrence the vnum and the code knows exactly what room to put the user in. For this reason a sequence container seems to be my only option. The same system is used for the objects and mobiles (characters that are not players). ----- Original Message ----- From: Ioannis Vranos To: dev...@li... Sent: Thursday, May 01, 2003 11:02 AM Subject: RE: [Dev-C++] 'extern const' and std::vector
-----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. 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. 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. My other question concerns the std::vector container class of the STD. 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? 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. :) In any case you have not to worry about these details. 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. Regarding constant random access with [] time cost: vector, deque, string, valarray and bitset have this. Reference for all the time costs for all containers for all types of access ([], front operations, etc): "The C++ Programming Language" 3rd Edition or Special Edition by Bjarne Stroustrup (the creator of C++): On page 464. Ioannis Vranos
* Programming pages: http://www.noicys.freeurlcom
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net
Anti-racism movement: http://www.positive-youthfoundation.org
Iraq Peace Pledge: http://www.peacepledge.org
---------------------------------
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo. |