Home » Community » Forums » General Programming » Magic numbers(NOT the begginer programming project)
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic


 Last Thread Next Thread 
 Magic numbers(NOT the begginer programming project)
Post New Topic  Post Reply 
hi. I recently read on another forum about something called magic numbers, in which if the program/game is using a certain amount of memory and there is a cetain amount of memory available on the computer, then the program/game will run twice as fast. is this correct? am i confusing it with something else? thanks.

______________________________
My website: Quest Networks

 User Rating: 1008   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

NO, you're confusing it!

 User Rating: 1203   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

You may be thinking of 'alignment issues'?

I don't suppose you could link to the relevant thread?

 User Rating: 1992   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Say you have a simple loop somewhere in your code...

for( int i=0; i<100; i++)
{
// do something
}

The number 100 is a 'magic number' and should be avoided.

Instead do:

const int MAX = 100;

for( int i=0; i<MAX ; i++)
{
// do something
}

Hope that helps...

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

a

 User Rating: 1015    Report this Post to a Moderator | Link

See
The Jargon File's definition

and

Wiki's MagicNumbers.

--------------------------------------------------------------------------------
I caught a plane to Spain, Went to a party down a red dirt road
There were lots of pretty people there, Reading Rolling Stone, reading Vogue

 User Rating: 1478   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

I dont have a link to the article. i was searching for some programming stuff in google months ago and stubled upon the artcile and cant seem to find it again. ill check out that artcile you posted, petewood. and Crazy Chicken, that code you posted wasn't really what i was looking for.

what is alignment issues? is that what its called? (not magic numbers?)

______________________________
My website: Quest Networks

 User Rating: 1008   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Alignment means aligning your data to 32 or 64 bit chunks that the CPU can handle faster thus speeding up your program. I'm not sure exactly what you meant from your orginal post however.

 User Rating: 1341   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

ok, ive never heard of that before. Ill try to clarify my original post. In the article I read, it talked about something called a "magic number". a magic number was basically if the amount of memory your program is using and the amount of memory on the computer, when added(or multiplied. i can't remeber) equal a certain number, called the magic number, Your program would then increase dramatically in performance. Was I more clear this time? I basically just want to know if something like this exists, and if it does, i wanted to know how it works.

______________________________
My website: Quest Networks

 User Rating: 1008   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

I think I know what you are talking about. Modern operating systems (e.g., Windows) run your program in a virtual address space, where as far as your program is concerned, it has the entire 32-bit range of memory to play in. It accomplishes this by organizing memory into "pages," and storing unused pages on the hard drive in a page or swap file. Pages are swapped in and out as needed.

If the size of your program and all its data fits into a single page (4096 bytes usually on Windows, I think?), then the OS won't have to do lots of page swapping while your program is getting a timeslice (although it will probably still swap when your program is not running and at the beginning of your timeslice).

I have my doubts as to how much performance increase you'll get by doing this, especially since 4KB is a pretty tight size restriction for a reasonably useful program.

I have never heard the term "magic number" in conjunction with this. What you want to look for is probably "virtual memory."

 User Rating: 1953   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

thanks, i think that was somewhat what i was looking for. However, I am 100% positive the term that was used was "magic number", so i have my doubts as to wether this is really what i was looking for or not. I know it wasnt virtual memory, i already know what that is. Thanks for posting that, though.

______________________________
My website: Quest Networks

 User Rating: 1008   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

People are often imprecise with terminology for this sort of thing, or flat out make it up. Again, a link to the thread would be helpful.

 User Rating: 1992   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

If you take a look at this google search you'll notice that LOTS of articles use the term "magic number" to describe lots of different things. "fuc.ing number" would mean exactly the same in any of those context.

 User Rating: 1351   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

ok, perhaps i mistook it for something else somehow. i dont have a link to the thread because it was actually a site i found searching through google months ago. i said it was a thread on accident.

______________________________
My website: Quest Networks

 User Rating: 1008   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Quote:
Original post by owl
If you take a look at this google search you'll notice that LOTS of articles use the term "magic number" to describe lots of different things. "fuc.ing number" would mean exactly the same in any of those context.


Heh.. owl, those are all pretty much the same concept of "magic number" though: some value that has no real definition or meaning and was apparently pulled out of nowhere.

cheers
sam.


 User Rating: 1164   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: