Skip to main content
gamedev.net
🔒 Locked

Magic numbers(NOT the begginer programming project)

Started by jakpandora 13 replies 2.9k views
Original Post
jakpandora
jakpandora
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
Radan
Radan
NO, you're confusing it!
-----------------Always look on the bright side of Life!
Zahlman
Zahlman
You may be thinking of 'alignment issues'?

I don't suppose you could link to the relevant thread?
Crazy Chicken
Crazy Chicken
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{
// do something
}

Hope that helps...
jakpandora
jakpandora
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
Rebooted
Rebooted
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.
jakpandora
jakpandora
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
jpetrie
jpetrie
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."
jakpandora
jakpandora
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
Zahlman
Zahlman
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.
owl
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.
[size="2"]I like the Walrus best.
jakpandora
jakpandora
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
izzo
izzo
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.