Re: [Dev-C++] 'extern const' and std::vector
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2003-05-01 14:39:11
|
I'm not too good at the latest updates of the standards, but to the best of my knowledge, there is no const extern declarations. Extern is just a keyword to inform the compiler that somewhere in another linking unit, the specified variable or function exists. However, you can not just lie, because when you reference the symbol, the compiler will insert a name-mangled reference and the linker will then fail if an exactly identical reference isn't available somewhere in one of the included object or library files. Because c++ uses name-mangling, you can't just change the declaration of a variable in your extern statement. There might be C++ compilers that doesn't change the name-mangling for a const contra non-const variable. In that case, this scheme would work for that compiler. However, I'm pretty sure that you would have to search a lot for a compiler with such a name-mangling. If, on the other hand, you declare the variable as "C", you can do just about anything, i.e. you might declare the variable as char in one source file and as unsigned long in another. Then it's up to you to figure out if the program will survive, or if it will go up in a big explosion when you try and run it. About 2^32 elements in a vector - I hope you are running a 64-bit operating system. Even a vector of 2^32 characters would fill the full address space of a 32-bit processor. Ever wondered about the big need of 64-bit processors and operating systems for large database applications? If I assume that you don't need 2^32 elements, just an address range of 2^32, I would suggest a slower (log n) solution using some form of btree or similar. Then you might traverse down the tree until you find the node containing the range, or no match is found. If you don't have to support ranges, but just want to either find an element, or know that it isn't there, go for a hash solution instead. It will perform insert and lookup operations in constant time. /Per W On Thu, 1 May 2003, David McKen wrote: > 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 fu= nctions in another file. However these other functions do not need (actuall= y I don't want them to have) write access to this variable, can I do someth= ing similar to 'const <var_type> <var_name>?'. For those of you who are won= dering 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.= 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 m= aximum size once there is no block of memory big enough to hold it's data? = 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 ge= ts 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 ra= nges. > > --------------------------------- > Do you Yahoo!? > The New Yahoo! Search - Faster. Easier. Bingo. |