A word about memory
A word about memory
This tutorial was intended to extend people's knowledge on what really goes on "behind the scenes" in scripts. I know this is probably not necessary since pawn is a scripting language, and knowledge of memory is not really needed. However, you'll find time and time again the "superior" programmers are the ones that have knowledge of how computers truly work. Please note, this is only scratching the surface though, and talks about how pawn works with memory, nothing more. What’s with the .amxx? I'm going to stray from the path a little bit, because I feel it's good that every AMXX scripter should know this. When I first began scripting for AMXX, I had no clue what a .amxx file was or how AMX Mod or AMXX got their names. AMX stands for Abstract Machine eXecutive, hopefully now you see where AMX and AMXX got their names. Their are two file types .amx and .amxx. This first one is the "original" file type pawn had. The .amx file type however is not compatible with 32 bit and 64 bit machines simultaneously and requires a special compile for each one. The .amxx file changes that and can be used on both machines with only one compile. Don't byte off more than you can nybble! Bits, nybbles, and bytes. If your reading this, you probably have no clue what those are. Lets examine: a bit is just a single digit in a binary number. Code:
10010010 Code:
We know that 8 bits is a byte, so lets divide by eight: Code:
32 bit: Code:
10110010 10000110 11000001 11110001 What's in a variable? As a programmer, variables are a must in programming, it's like virtual water. But what really is a variable? We know it can hold data, like integers, floats, and boolean types; sadly though, this is the only thing most beginning to intermediate level scripters know. Pawn revolves around a single data type, the cell which is 4 or 8 bytes depending if the machine is a 32 bit or 64 bit machine. Also, cells are signed. Code:
You should know what this does, it declares a variable named var that can hold an integer. Now, this is what really happened, the VM (Virtual Machine) will allocalate one cell. Remember cells are 4 or 8 bytes depending on the machine. Hurray! Now you've probably started to catch on what’s going on "behind the scenes"! Arrays - How do you fit everything in there? An array is just a big area of memory that holds a bunch of variables stacked on top of each other. The first element (i.e. a[5] would be the fifth element) really "points" to the beginning of the array. Here is what one could visualize an array as filled with some values: http://www.fredosaurus.com/notes-cpp...v2_145x215.gif But wait, how do you get from here (a[0]) to there (some other element like a[5])? A simple calculation of course! Using the size of a cell, the VM can calculate an offset from the base of the array, to the location of the area of memory you want access to. Example: Code:
I want to access element three. Here is what you could visualize it as: http://www.cs.vassar.edu/~cs102/lect...s/array-2d.png Different Data Types I'm not going to go into this topic to deep. Pawn only has knowledge of one data type as you should know by now, the cell. But what about floats or booleans? To overcome this, pawn "tags" variables, but they are still treated as cells. Booleans as you know only hold two values, true or false, one or zero. Any number past or below these are invalid. As for floats, they go beyond the length of this tutorial. However, Pawn uses the IEEE standard for floating point arithmetic, which you can learn more about here. If I made any mistakes in this tutorial or this tutorial is complete crap, please PM me via AMXX. |
Re: A word about memory
Yes it is my first tutorial, thank you :).
|
Re: A word about memory
You're wrong about the VM processing tags differently. Tags are basically just a futile attempt by the compiler to make things other than cells. Once compiled, there are no tags - everything is processed by the VM as a cell.
EDIT: Also, bools CAN hold any number in Pawn, they just get a tag mismatch or something to that effect. Here is a proof of concept script: Code:
|
Re: A word about memory
Quote:
And yes I know about the boolean thing, thats why I said it would "invalid", because you can cast them to get around them, like you did. |
Re: A word about memory
You are wrong about the sizes of bytes, nybbles, and word sizes (how much a CPU can process/store at one time).
The size of a byte is non-standardized. Many archetectures use 4 bit bytes (stores one hexidecimal value) and 6 bit bytes (makes it easier to do some operations). The nybble, which is based on the byte, is also non-standardized. Any code relying on the byte being 8 bits isn't portable to CPU's that use 4/6 bit bytes, which a lot of smaller appliances (cell phones for instance) and such use. On the topic of word sizes (a word is how big a register is in the CPU, and in effect, the largest peice of data that the CPU can process in one OP code), you are mistaken, though your assumption is not nessasarily a bad one. A 32-bit processor can work on more than 32-bits at a time; it just does it in 32-bit chunks. The defining quantity than, is the size of the registers, which are generally the same size as the processor, but which can be larger or smaller. For instance, some of the game consoles like Saturn, N64, and PSX had variable word sizes, and could thus process big floating points with as much ease, though a little less speed, than if they had a bigger, more expensive processor size. No offense or anything; the assumption that a byte is 8 bits is pretty much standard with PC's, and the other part wasn't too far off. Just technicalities really, nice job. |
Re: A word about memory
Suzuka, I didn't right this tutorial for cell phones or game consoles :P. Although, I really had no clue about that stuff.
Quote:
I'm not trying to argue back, just trying to clear some stuff up, since I'm like 1/4 the programmer you are :/. |
All times are GMT -4. The time now is 08:46. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.