|
There are a few ways I can think of, but it's hard without more information.
1. Don't store it as text, save them as binary groups of four bytes
2. Only store the changes between each digit (0.0.0.[x0, x1, .. x254, x255], 0.0.1.[x0, x1, .. x254, x255], ...)
3. Don't save them at all, just generate them on the fly, this would be ideal but it depends on your situation.
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
Snyp wrote:
ALL the ip's that are possible...
I second Andrew's suggestion: there's no need to store these on disk - simply generate them on the fly.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
I just wanted to do this for fun, to see what and how large it would be, I have a 30 gig hard drive and I calculated the document to come out aproximatly 50 gigs!!!!
Actual Linux Penguins were harmed in the creation of this message.
|
|
|
|
|
You know there are 4 billion of them, generating them is like counting from 0-0xffffffff. Uncompressed binary storage would require 16GB.
But making a computer count from 0-4 billion seems rather pointless.
Paul
|
|
|
|
|
Paul Ranson wrote:
But making a computer count from 0-4 billion seems rather pointless.
That reminds me of the time I had two computers: a Commodore 64 (which had a clock speed of 1.02 MHz), and a 12 MHz AT-Compatible PC. I used to code up identical (sorting) programs in basic and watch them run. Yes it was pointless, and I never understood why the C64 never won at least a few times! It just didn't seem fair.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Unless you actually needed them for something, there are 232 possible addresses, but not all of those are valid. Assuming each address is 15 bytes, you could store 13,981,013 within a 200MB file.
However, since an IP address is also a 32-bit value, you could store it as a 32-bit value instead. Now that 200MB file can store 52,428,800 addresses.
for (unsigned int x = 0; x < UINT_MAX; x++)
fwrite(&x, sizeof(x), 1, ...);
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Hi, i want an article about memory allocation. What the best way to allocate memory in:
1. COM+;
2. COM;
3. Multithread enviroment ( COM e COM+);
5. i should use new and delete when ? heap ? malloc ?;
6. console aplication;
7. C and C++.
thanks for help.
|
|
|
|
|
Hi all ..
How i can convert string "arabic" to UCS-2 encoding ?
Best Regards,
Rasha
|
|
|
|
|
|
no i am going to use Unicode character-coding where each char stored in 2 byte so i load my string like that :
wchar_t * pwszMyString = "This is my wide character string";
then if i am going to use MultiByteToWideChar() which code page i have to use to convert the string to UCS2 coding ?
|
|
|
|
|
|
ok until now i got the UCS-2 then how i can get the hex representation for each charachter in 2 byte ,, like
A
|
00 61
i tride that for english it works but in arabic like
ب
|
06 28 ( the right value i should have )
insted of this value i am getting
00 C8
this mean it keep using 1 byte as i think ? what is the logic i can use to get the correct value?
|
|
|
|
|
allocator is abstract to me,how do you understand it?please explain some for it,thanks
in addition,please look:(1) list<int> c1;
(2) list<int> c2(5,3);
(3) list<int> c3(3,1,c2.get_allocator());
my question:
A.(1) and (2) use the default allocator to construct list?
B. if A is yes,then (3) still use the default allocator only chaging a showing form.
C.if A,B are yes,then only we ourselves define allocator ,that way,if write get_allocator is really useful.
if i said above has wrong ,please rectify,thx!
|
|
|
|
|
A -> YES.
B -> YES.
C : ... i don't know more about allocators, but if anybody here could answer about the aim of user defined allocators, that would help...
TOXCCT >>> GEII power
|
|
|
|
|
I am using fgets to get a character array, and then looping through to split it into words by spaces with strtok. For the next step, I am creating a control structure based upon those words. I seem to be able to get the first word but not the next using _strnicmp. It doesn't reuturn 0 when there is a match. I am assuming there is some control character involved that I'm not seeing. Part of the byte is that it has to be C (not C++) and use any non-standard libraries.
So, my question is - how do I do that
and 2, isn't tjhere a better way like a case statement with strings?
I would appreciate any help I can get. Thanks.
Here's the code I have so far:
<br />
<br />
#include <stdio.h><br />
#include <stdlib.h><br />
#include <string.h><br />
#include <mbstring.h><br />
<br />
<br />
char waitkey [10];<br />
char *pch;<br />
<br />
struct map {<br />
char *name;<br />
char *description;<br />
int north;<br />
int south;<br />
int west;<br />
int east;<br />
int up;<br />
int down;<br />
int other;<br />
};
struct map my_map[20] = {<br />
{"Location0", "Dummy Location", 0,0,0,0,0,0,0},<br />
{"Location1", "Admissions", 2,0,0,0,0,0,0},<br />
{"Location2", "Lovely Lounge", 3,1,0,0,0,0,0},<br />
{"Location3", "Main Hallway", 3,1,0,0,0,0,0},<br />
{"Location4", "TV Room", 0,0,0,0,0,0,0},<br />
{"Location5", "Mess Hall", 0,0,0,0,0,0,0},<br />
{"Location6", "Crafts Room", 0,0,0,0,0,0,0},<br />
{"Location7", "Therapy Room", 0,0,0,0,0,0,0},<br />
{"Location8", "Padded Cell", 0,0,0,0,0,0,0},<br />
{"Location9", "Mike's Room", 0,0,0,0,0,0,0},<br />
{"Location10", "Nurse's Station", 0,0,0,0,0,0,0},<br />
{"Location11", "Group Therapy Room", 0,0,0,0,0,0,0},<br />
{"Location12", "Fenced Patio", 0,0,0,0,0,0,0},<br />
{"Location13", "Showers", 0,0,0,0,0,0,0},<br />
{"Location14", "Violent Ward", 0,0,0,0,0,0,0},<br />
{"Location15", "Honest Politician's Ward", 0,0,0,0,0,0,0},<br />
{"Location16", "Depressed College Student's Ward", 0,0,0,0,0,0,0},<br />
{"Location17", "Phone Booth", 0,0,0,0,0,0,0},<br />
{"Location18", "Secret Ritual Room", 0,0,0,0,0,0,0},<br />
{"Location19", "Psychiatrist's Lounge", 0,0,0,0,0,0,0}<br />
};
<br />
int current_room = 1;<br />
<br />
int main(int argc, char* argv[])<br />
{ <br />
printf("*** Josh's fantastic escape from the C Sanitarium for burnt out Coderz ***\n");<br />
printf("\n\n");<br />
printf("LOCATION : %s\n", my_map[current_room].name);<br />
printf("DESCRIPTION : %s\n",my_map[current_room].description);<br />
printf("WHAT'S HERE :\n");<br />
printf("VISIBLE EXITS:");<br />
<br />
if (my_map[current_room].north >= 1)<br />
{<br />
printf("North ");<br />
}<br />
<br />
if (my_map[current_room].south >= 1)<br />
{<br />
printf(" South ");<br />
}<br />
if (my_map[current_room].west >= 1)<br />
{<br />
printf(" West ");<br />
}<br />
if (my_map[current_room].east >= 1)<br />
{<br />
printf(" East ");<br />
}<br />
if (my_map[current_room].up >= 1)<br />
{<br />
printf(" Up ");<br />
}<br />
if (my_map[current_room].down >= 1)<br />
{<br />
printf(" Down ");<br />
}<br />
if (my_map[current_room].other >= 1)<br />
{<br />
printf(" Other ");<br />
}<br />
printf("\n");<br />
printf("\nWhat would you like to do?\n");<br />
char user_command[250];<br />
fgets(user_command, sizeof(user_command), stdin);<br />
fflush(stdin);
printf("\n");<br />
char *words[11];<br />
int wordnumber = 0;<br />
char *pch;<br />
pch = strtok (user_command, " ");<br />
words[wordnumber]=pch;<br />
while ((pch != NULL) && (wordnumber < 10))
{<br />
wordnumber++;<br />
words[wordnumber]=pch;<br />
pch = strtok (NULL, " ,.");<br />
}<br />
int count;<br />
for(count=1;count<=wordnumber;count++)<br />
{<br />
printf("**%s**\n",words[count]);<br />
}<br />
<br />
int result;<br />
char go[] = "go";<br />
result = _strnicmp(words[0], go, 2 );<br />
<br />
if (result==0)<br />
{<br />
printf("You want to go somewhere\n");<br />
char north[] = "north";<br />
char south[] = "south";<br />
char west[] = "West";<br />
char east[] = "east";<br />
char up[] = "up";<br />
char down[] = "down";<br />
char other[] = "other";<br />
<br />
int result;<br />
result = _strnicmp(words[1], north, 5 );<br />
if (result==0)<br />
{<br />
printf("You want to go north\n");<br />
}<br />
result = _strnicmp(words[1], south, 5 );<br />
if (result==0)<br />
{<br />
printf("You want to go south\n");<br />
}<br />
result = _strnicmp(words[1], west, 4 );<br />
if (result==0)<br />
{<br />
printf("You want to go west\n");<br />
}<br />
result = _strnicmp(words[1],east, 4 );<br />
if (result==0)<br />
{<br />
printf("You want to go east\n");<br />
}<br />
result = _strnicmp(words[1], up, 2 );<br />
if (result==0)<br />
{<br />
printf("You want to go up\n");<br />
}<br />
result = _strnicmp(words[1], down, 4 );<br />
if (result==0)<br />
{<br />
printf("You want to go down\n");<br />
}<br />
result = _strnicmp(words[1], other, 5 );<br />
if (result==0)<br />
{<br />
printf("You want to go north\n");<br />
}<br />
}<br />
char blow[]="blow";<br />
result = _strnicmp(words[0], blow, 4 );<br />
if (result==0)<br />
{<br />
printf("blow");<br />
}<br />
<br />
<br />
return 0;<br />
}<br />
|
|
|
|
|
You almost had it right! The problem lies in the organization of your while loop. Try this instead:
while ((pch != NULL) && (wordnumber < 10))
{
++wordnumber;
pch = strtok (NULL, " ,.");
words[wordnumber]=pch;
}
Regards,
|
|
|
|
|
I to tired to study your code but I have the following comments:
First you need to use if else statments, because once a test has been passed there in no need for more testing. Second the comments are C++ comments, which start wit "//" and do not end with anything, although you are ending them with "//"; your comments in C should start with "/*" and end with "*/
".
Now you need to understand how strtok works!
while ((pch != NULL) && (wordnumber < 10))// and word # is acceptable - add later//
{
wordnumber++;
words[wordnumber]=pch;
pch = strtok (NULL, " ,.");
}
What strtock does is set a global pointer to the start of your string on the first call. When it finds a dilimeter it temporaraly replaceses it with a '\0' character and returns a pointer to the start of the token. On the next call it restores the delimiter, and sets the global pointer to the start of the next token (if any). It then looks for the next delimiter and repeats the process.
Note: The first argument is not a constant, what that means is it is changing the string (temporarily). If I typed in a string like so, "north south east west" then your code would produce the following strings:
1) "north south east west"
2) "south east west"
3) "east west"
4) "west"
To understand string functions, just sit down and recreate them!
I was going to write a quick strtok function to show you but it is after 4 AM here and my mind told me where I could put that idea (best not repeated here).
Good Luck!
INTP
|
|
|
|
|
Much appreciated. I changed the comments to C syntax. It's true that I'm not doing proper captue yet (the else statements) but I was hoping to find a better way. Rather than change the while statement I just adapted the bottom so subscripts match. I'm going to see if there is some way I could ste this up with a switch statement. Any suggestions (especially for a better way of processing commands) are much appreciated.
<br />
<br />
<br />
#include <stdio.h><br />
#include <stdlib.h><br />
#include <string.h><br />
#include <mbstring.h><br />
#include <dos.h><br />
<br />
#define CR 0x0d<br />
#define ESC 0x1b<br />
#define TAB 0x09<br />
#define LF 0x0a<br />
#define BACKSPACE 0x08<br />
#define NULL 0<br />
#define TRUE 1<br />
#define FALSE 0<br />
#define LENGTH 80<br />
#define COLS 80<br />
#define VIDEO 0x10<br />
#define ROWS 25<br />
#define DELAY 250<br />
#define MROW 12<br />
<br />
void refresh(void);<br />
void process_command(void);<br />
void main_thing(void);<br />
void cls(void);<br />
<br />
<br />
char user_command[250];<br />
char waitkey [10];<br />
char *pch;<br />
<br />
struct map {<br />
char *name;<br />
char *description;<br />
int north;<br />
int south;<br />
int west;<br />
int east;<br />
int up;<br />
int down;<br />
int other;<br />
}; <br />
struct map my_map[22] = {<br />
{"Location0", "Dummy Location", 0,0,0,0,0,0,0},<br />
{"Location1", "Admissions", 2,0,10,17,0,0,0},<br />
{"Location2", "Lovely Lounge", 3,1,5,4,0,0,0},<br />
{"Location3", "Main Hallway", 20,2,6,13,0,0,0},<br />
{"Location4", "TV Room", 0,0,2,19,0,0,0},<br />
{"Location5", "Mess Hall", 6,0,12,2,0,0,0},<br />
{"Location6", "Crafts Room", 0,5,11,3,0,0,0},<br />
{"Location7", "Therapy Room", 0,0,0,20,0,0,0},<br />
{"Location8", "Padded Cell", 0,0,20,0,0,0,0},<br />
{"Location9", "Mike's Room", 0,0,16,0,0,0,0},<br />
{"Location10", "Nurse's Station", 0,0,0,1,0,0,0},<br />
{"Location11", "Group Therapy Room", 0,0,0,6,0,0,0},<br />
{"Location12", "Fenced Patio", 0,0,0,5,0,0,0},<br />
{"Location13", "Showers", 0,0,3,0,0,0,0},<br />
{"Location14", "Violent Ward", 0,0,0,21,18,0,0},<br />
{"Location15", "Honest Politician's Ward", 0,21,0,0,0,0,0},<br />
{"Location16", "Depressed College Student's Ward", 0,0,21,9,0,0,0},<br />
{"Location17", "Phone Booth", 0,0,1,0,0,0,0},<br />
{"Location18", "Secret Ritual Room", 0,0,0,0,0,14,0},<br />
{"Location19", "Psychiatrist's Lounge", 0,0,4,0,0,0,0},<br />
{"Location20", "Hallway part 2", 21,3,7,8,0,0,0},<br />
{"Location21", "Hallway part 3", 15,20,14,16,0,0,0}<br />
}; <br />
<br />
<br />
int current_room = 1;<br />
<br />
int main(int argc, char* argv[])<br />
{ <br />
<br />
refresh();<br />
process_command();<br />
<br />
<br />
return 0;<br />
<br />
}<br />
<br />
void refresh(void)<br />
{<br />
<br />
cls();<br />
printf("*** Josh's fantastic escape from the C Sanitarium for burnt out Coderz ***\n");<br />
printf("\n\n");<br />
printf("LOCATION : %s\n", my_map[current_room].name);<br />
printf("DESCRIPTION : %s\n",my_map[current_room].description);<br />
printf("WHAT'S HERE :\n");<br />
printf("VISIBLE EXITS:");<br />
<br />
<br />
if (my_map[current_room].north >= 1)<br />
{<br />
printf("North ");<br />
}<br />
<br />
if (my_map[current_room].south >= 1)<br />
{<br />
printf(" South ");<br />
}<br />
if (my_map[current_room].west >= 1)<br />
{<br />
printf(" West ");<br />
}<br />
if (my_map[current_room].east >= 1)<br />
{<br />
printf(" East ");<br />
}<br />
if (my_map[current_room].up >= 1)<br />
{<br />
printf(" Up ");<br />
}<br />
if (my_map[current_room].down >= 1)<br />
{<br />
printf(" Down ");<br />
}<br />
if (my_map[current_room].other >= 1)<br />
{<br />
printf(" Other ");<br />
}<br />
<br />
printf("\n");<br />
printf("\nWhat would you like to do?\n");<br />
<br />
fgets(user_command, sizeof(user_command), stdin);<br />
fflush(stdin);<br />
printf("\n");<br />
}<br />
void process_command(void)<br />
{<br />
<br />
<br />
char *words[11];<br />
int wordnumber = 0;<br />
char *pch;<br />
pch = strtok (user_command, " ");<br />
<br />
words[wordnumber]=pch;<br />
<br />
while ((pch != NULL) && (wordnumber < 10))
{<br />
wordnumber++;<br />
words[wordnumber]=pch;<br />
pch = strtok (NULL, " ,.");<br />
}<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
int result;<br />
char go[] = "go";<br />
result = _strnicmp(words[1], go, 2 );<br />
<br />
if (result==0)<br />
{<br />
<br />
char north[] = "north";<br />
char south[] = "south";<br />
char west[] = "West";<br />
char east[] = "east";<br />
char up[] = "up";<br />
char down[] = "down";<br />
char other[] = "other";<br />
<br />
int result;<br />
result = _strnicmp(words[2], north, 5 );<br />
<br />
if (result==0)<br />
{<br />
<br />
if (my_map[current_room].north >= 1)<br />
{<br />
current_room = my_map[current_room].north;<br />
<br />
main_thing();<br />
}<br />
else<br />
{printf("Can't go there!\n");<br />
}<br />
}<br />
result = _strnicmp(words[2], south, 5 );<br />
if (result==0)<br />
{<br />
<br />
if (my_map[current_room].south>= 1)<br />
{<br />
current_room = my_map[current_room].south;<br />
<br />
main_thing();<br />
}<br />
else<br />
{printf("Can't go there!\n");<br />
}<br />
}<br />
result = _strnicmp(words[2], west, 4 );<br />
if (result==0)<br />
{<br />
<br />
if (my_map[current_room].west >= 1)<br />
{<br />
current_room = my_map[current_room].west;<br />
<br />
main_thing();<br />
}<br />
else<br />
{printf("Can't go there!\n");<br />
}<br />
}<br />
result = _strnicmp(words[2],east, 4 );<br />
if (result==0)<br />
{<br />
<br />
if (my_map[current_room].east >= 1)<br />
{<br />
current_room = my_map[current_room].east;<br />
<br />
main_thing();<br />
}<br />
else<br />
{printf("Can't go there!\n");<br />
}<br />
}<br />
result = _strnicmp(words[2], up, 2 );<br />
if (result==0)<br />
{<br />
<br />
if (my_map[current_room].up >= 1)<br />
{<br />
current_room = my_map[current_room].up;<br />
<br />
main_thing();<br />
}<br />
else<br />
{printf("Can't go there!\n");<br />
}<br />
}<br />
result = _strnicmp(words[2], down, 4 );<br />
if (result==0)<br />
{<br />
<br />
if (my_map[current_room].down >= 1)<br />
{<br />
current_room = my_map[current_room].down;<br />
<br />
main_thing();<br />
}<br />
else<br />
{printf("Can't go there!\n");<br />
}<br />
}<br />
result = _strnicmp(words[2], other, 5 );<br />
if (result==0)<br />
{<br />
<br />
if (my_map[current_room].other>= 1)<br />
{<br />
current_room = my_map[current_room].north;<br />
<br />
main_thing();<br />
}<br />
else<br />
{printf("Can't go there!\n");<br />
}<br />
}<br />
}<br />
char blow[]="blow";<br />
result = _strnicmp(words[1], blow, 4 );<br />
if (result==0)<br />
{<br />
printf("you typed blow");<br />
}<br />
}<br />
void main_thing(void)<br />
{<br />
refresh();<br />
process_command();<br />
}<br />
void cls( void )<br />
{<br />
system("cls");<br />
}<br />
|
|
|
|
|
Hello.
I'm writting application which Open an Access database via OLE DB.
And I want to receave all column metadata With 'IColumnsInfo2::GetRestrictedColumnInfo(...)' , but I cannot(or don't know how) implement IColumnsInfo2 with 'IColumnsRowset'.
i.e.
--------------------------------
IColumnsRowset** ppOLEColumnsInfo;
IColumnsInfo2** ppOLEColumnsInfo2;
.............
HRESULT hr = ppOLEColumnsInfo->QueryInterface(IID_IColumnsInfo2,(void**)ppOLEColumnsInfo2)
//and hr == E_NOINTERFACE
--------------------------------
............
If i try to add 'DBPROP_IColumnsInfo2' property while open 'IColumnRrcorset' with 'IOpenRowset::OpenRowset', result is 'DB_S_ERRORSOCCURRED'.
i.e.
--------------------------------
IOpenRowset** ppOLEOpenRowset;
IColumnsRowset** ppOLEColumnsInfo;
..........
DBPROPSET dbPropSet[1];
ULONG cDbPropCount = sizeof(dbPropSet)/sizeof DBPROPSET;
const ULONG cProperties = 1;
DBPROP rgProperties[cProperties];
pPropSet->rgProperties = rgProperties;
pPropSet->cProperties = cProperties;
pPropSet->guidPropertySet = DBPROPSET_ROWSET;
AddProperty(&rgProperties[1] ,DBPROP_IColumnsInfo2,VT_BOOL,VARIANT_TRUE,DBPROPOPTIONS_OPTIONAL);//doesn't work with DBPROPOPTIONS_REQUIRED, too
............
hr = pOLEOpenRowset->OpenRowset(NULL,&dbID,NULL,IID_IColumnsRowset,
1 ,&dbPropSet,(IUnknown **)&pOLEColumnsRowset );
//and hr == DB_S_ERRORSOCCURRED
//and dbPropSet.rgProperties.dwStatus == DBPROPSTATUS_NOTSUPPORTED
--------------------------------
So, how can i implement Rowset which can implement IDBColumnInfo2 ?
thanks at advice:
KalliMan
a
|
|
|
|
|
Hi all,
This might be a simple question, and you might say that both ways have their own pros and cons (and the pros and cons are so minor, that they are negligible, therefore they are virtually equally efficient). But sometimes I wonder if every single bit of memory and every cpu cycle count, which one is better?
Thanks for any input.
<br />
for(int i=0; i<myArray.GetSize(); i++)<br />
{<br />
if(myArray.GetAt(i).GetValue()==1) { Function1(); }<br />
else if(myArray.GetAt(i).GetValue()==2) { Function2(); } }<br />
else { Function3(); }<br />
}<br />
<br />
for(int i=0; i<myArray.GetSize(); i++)<br />
{<br />
int nValue = myArray.GetAt(i).GetValue();<br />
if(nValue==1) { Function1(); }<br />
else if(nValue==2) { Function2(); }<br />
else { Function3(); }<br />
}<br />
|
|
|
|
|
The answer is, it depends .
If the value returned by <nobr>myArray.GetAt(i).GetValue() is 1, then the two methods will probably have equivalent performance. The fact that you've got a named temporary variable in method 2 doesn't affect the performance, since the compiler generates a temporary variable to hold the return value in method 1.
If the value returned by <nobr>myArray.GetAt(i).GetValue() is >= 2, method 2 will probably execute faster. In method 1, the compiler will generate two calls to <nobr>myArray.GetAt(i).GetValue() . Method 2 only uses a single call. The fact that the function call probably returns the same value is irrelevant, since the compiler can not make that assumption, and therefore must generate and execute code for two calls.
If <nobr>myArray.GetAt(i).GetValue() does not have side effects, then it's safe to assign its value to a temporary and use that, as in method 2.
If <nobr>myArray.GetAt(i).GetValue() does have side effects (successive calls with the same arguments do not return the same results), then you must use method 1.
Software Zen: delete this;
|
|
|
|
|
...but i would like to add
for(int i=0; i<myArray.GetSize(); i++)
myArray.GetSize() is called in every loop, so there is another method call in every loop. you can avoid that by using a temp variable there if the count/loop is large.
I'll write a suicide note on a hundred dollar bill - Dire Straits
|
|
|
|
|
Joe Smith IX wrote:
for(int i=0; i<myArray.GetSize(); i++)
{
int nValue = myArray.GetAt(i).GetValue();
if(nValue==1) { Function1(); }
else if(nValue==2) { Function2(); }
else { Function3(); }
}
How about,
int size = myArray.GetSize ();
for ( int i = 0; i < size; ++i )
{
switch ( myArray.GetAt ( i ).GetValue ())
{
case 1 :
Function1 () ;
break ;
case 2 :
Function2 () ;
break ;
default :
Function3 () ;
break ;
}
}
But if efficiency is relevant the whole structure needs examination.
Paul
|
|
|
|
|
Method (1) is dangerous - it requires that GetValue() has no side-effects. This makes for code that's hard to maintain.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
First, the line else if(myArray.GetAt(i).GetValue()==2) { Function2(); } } has an extra brace at the end.
In actual performance the two are identical since they compile to the same thing (at least in VC++ 7.1, but likely also in VC++ 6.0.)
Incidentally, using a switch statement is slightly slower. If there were additional cases, that could change.
[EDIT: At Tim correctly points out, my answer is correct only to the narrow stipulation given. Since GetValue() could involve more than the return of a simple value, it is best to get the value first then test it. The exception would be IF side effects are documented and each test depends on those side effects, though that would be a very odd solution indeed.]
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|