Are Arrays Global?
-
@CAnesia @Aidan-Oxley
Arrays: In English... Part 1!
Imagine a road that goes forever over a flat plain. and there’s nothing there. Kind of like SimCity before you build anything. Just a huge expanse of nothing, with a road through it.
That’s unused memory.
Where we put things along that road is going to have an address. You’re the first person in this new land, so you build a house somewhere along this road, and number it:
Number 1, Memory Road,
Your friends come visit and they like your house. And the road. And the empty wasteland around it.
So you give them the plans to your house, and the same amount of land as you have, and they all build houses, one after another, along the road, straight up from your place.
They’re address numbers 2 through 16 along this road. Their houses are slightly different and their BBQ’s each very different, and they all buy furniture you don't understand and eat weirdly, but the amount of land they use up is all the same. Kind of like a modern gated community.
Capitalism bringing us the conformity of communism without the social protections. Yippee.
Because each house has its own number, and is exactly the same size, the newspaper delivery boy can ride past on his bike each morning, simply reaching into his basket and throwing papers into the yards of each house without thinking.
It's SUPER simple for him. He rides at the same rate, pretty much looks straight ahead, and just reaches into the basket at a regular rate and throws a paper over his shoulder into each yard. Without thinking.
Whilst singing out-loud, with headphones on. "You're gonna hear me Rooooaaaaar....."
EASY! Even a moron can do it.
The newspaper delivery boy loves this route because it’s the easiest 16 houses. Straight line, no thinking, just throw the papers at a regular rate whilst coasting at a regular speed on his bike.
This is how computers see arrays. They LOVE them.
-
@Aidan-Oxley
I need both explanations and your post described good enough for me to at least understand when to use it ... Thanks! -
@Deeeds
Yay! A very nice part 1 - one thing I assumed about them and you nailed it: CPU loves them (speed).Am I very wrong if I describe and think of an Array as a Excel sheet? - that is what I have in mind when I read something or hear Array
Looking forward for the part 2
For my curiosity: is clear that you are a “Vizard” and hyperPad is a joke for your level so why are you on hyperPad? Don’t get me wrong I surely appreciate you are a part of it ...
-
@CAnesia said in Are Arrays Global?:
For my curiosity: is clear that you are a “Vizard” and hyperPad is a joke for your level so why are you on hyperPad? Don’t get me wrong I surely appreciate you are a part of it ...
Thank you. You're wrong.
There are many partial answers to this question, none of which, in isolation, lead to a useful or meaningful response.
But one of them is definitely that I'm NOT a "Vizard".
I look like Karl Marx. But much bigger, in every direction, and am prone to far more arrogance and contempt.
I'm fond of telling people that "I'm in marketing", laced with an enormous amount of disdain for myself, and marketing.
It is the best explanation of what I do, and who I am. Particularly if you can grasp that marketing is really about controlling products, more than anything else, because it's a verb.
Game engines and interactivity creativity applications are the next wave of meaningful tools for a fast approaching era where we shrug off the chains of social networking.
To this day, cocos2D-iPhone remains a valid 2D game engine because Apple completely dropped the ball on Sprite Kit.
Chipmunk2D is nowhere near threatened by Box2D, it's vastly superior for most applications. And its founder and creator is a gentleman and a scholar.
HOWEVER... cocos2D-iPhone has a couple of glaring bugs in it, a legacy of its origin and the last of three founders having left before it was sufficiently trailed in the modern era of iOS... wherein Apple made some dramatic changes to underlying systems in order to prepare for their future, which we're in now with the 120fps iPads.
hyperPad is based on cocos2D-iPhone and Chipmunk, but only really glances the surface of what they're capable of.
It is an interesting project, held back by...
-
@Deeeds
I found this post which is great in helping my array understandings, but I really enjoyed your part 1 written previously so please get the part 2 posted ... please!
You can't add an item at index location 5. It's simply impossible. You can't even add one at index 4, because that doesn't yet exist. But you can ~append~ item to the array. This extends out the array adding more space for itself, and makes an extra index. Now your new object is stored at index 4.
And arrays are super sensitive to the order in which things are stored, being absolute sticklers for this detail is both their massive advantage (reliability and predictability) and their short coming, because re-ordering or shuffling an array requires a lot of operations. The order of objects in an array gives it structure and meaning, as you can always be sure that what you want is where you put it, in the order you put everything in, so you can always know what's next... and so can your CPU and memory system.
Modern computers do an enormous amount of "predictive" processing, and iterating over an array (let's say, adding a 10 to every item in an array) is something that they're VERY good at, as they'll quickly figure out the space between each item and that the iteration is happening, and grab whole chunks of the array early, before instructions come in, and start working on them before being explicitly asked, presuming the results are going to be needed.
This is of enormous benefits to games, where every frame requires exactly this sort of operation to move all the objects in a game world.
So if you ever get the chance to use arrays for positions, rotations, interactions, etc... then do. Use them as much as you can.
Thanks!
-
@CAnesia I will. Sorry for the delay.
Have several ideas on where to go next with the road metaphor, but need a moment of inspiration.
There's much to cover with arrays, and they're the most important computing construct for games. Plus they're a bit extra special in hyperPad, because they really do seem to be global.
-
Because you were the first person to build in this world, you’re also the media magnate. You OWN the newspaper. The newspaper delivery boy works for you. So do the writers and the photographers. Which are all you, at this early stage of your town.
Aunt Betsy, in House Number 16, she’s decided you should install phones, cause she’s sick of walking to your place to complain about the Newspaper Delivery Boy throwing her morning paper in her little duck pond. You know he’s aiming for the pond because you’d told him too. You don’t like ducks.
Well... that’s what you told the Paper Delivery Boy. It motivates his devious side to know his employer has permitted him to upset that duck.
The truth is even more devious. You’re able to hear that duck quack from your house every time a newspaper lands in its pond. The duck quacks and flaps loud! This permits you to measure how long it takes the Paper Delivery Boy to deliver to your family and friends, from the sound of the first paper hitting your lawn, all the way out to Aunt Betsy’s house at the end of the row, and her duck getting its feather’s ruffled.
From this stopwatch recording of delivery times, you’ve got a good idea how many houses the Paper Delivery Boy should be able to deliver to each day. So Aunt Betsy’s duck is the signal that helps with the planning of the next great suburban expansion you’ve got planned. Every media magnate wants for nothing more than a larger audience and more sway over them. More on that later.
In the meantime, you probably owe it to Aunt Betsy to get her a home phone.
You think about it, and decide this is a good idea. New phones for each of your family and friends. All 16 houses. That'll make everyone happy, and make communication super easy. No more walking outside, knocking on doors and seeing if anyone is at home, leaving messages on doors and keys under mats. A simpler, more modern life awaits, just a home phone away.
You consider phone numbers, and think of yourself first. Not the wrong thing to do in this situation. Nor at all unusual for someone writing code, nor those prone to running a newspaper.
And you think… "how about sequential numbers for the phones, just like the house numbers on the road…"
Your phone number would be:
999 NeverYouMind 0001
You think this is a long number, so you abbreviate:
999 NYM 0001
This could work, you think…
999 NYM 0002
999 NYM 0003
999 NYM 0004
999 NYM 0005etc.
all the way to Aunt Betsy:999NYM 0016
This way, when Aunt Betsy calls you, you can see the number and know it’s her because it’s the same last two digits as her house address. Simple.
And ideal.
You call the phone company to get the lines and phones installed.
You ask for 16 sequential phone numbers. The phone company employee is ecstatic. “We just started a special on buying a group of numbers. 16 is just $200 and we can rush the install."
Ok. Cool.
All Good.
She talks you through it. Your numbers will be…
999 NYM 0000
999 NYM 0001
999 NYM 0002through to…
999 NYM 0015
You break her pace. “Sorry, can we start the group of numbers at 0001? I want them to match our house numbers.”
The phone company employee is disgruntled. “What? That’s weird. All our number groups start with 0000. You will have to buy another group of 16 numbers if you also want 0016, which means you want 32 sequential numbers, for which we charge $5000. It’s a corporate product."
DOH!
You buy the 16 pack, starting with 0000, and assign them to your family and friends houses… despite the offset.
So your phone number and house addresses look like this:
NYM 0000 : 1 Memory Road NYM 0001 : 2 Memory Road NYM 0002 : 3 Memory Road NYM 0003 : 4 Memory Road NYM 0004 : 5 Memory Road
-
Very good reading I really enjoy this ... please continue but don’t feel pressured into it. I never had a tutorial to follow with a twist like this so just go on at your own pace.
I’ll be waiting as long as needed.
Thank you! -
@Deeeds
To recap a bit: Array are a straight road with addresses (on left and right or only on one side?), so because it is straight and wide the CPU speeds on it like my AMG on Autobahn and we both enjoy that speed.
My CPU is 12 cores with a large buffer therefore it will remember the Autobahn and all the addresses in an instant. Moreover the addresses are always sequential numbers therefore my CPU knows exactly the location of my car at any given instant... -
@CAnesia I'll have to have a little think. This isn't where I was going with this. I was trying to introduce a range of complimentary ideas and aspects of programming in a subtle, inconspicuous manner, then reveal what they are later. Perhaps that's loading to much obscurity and layering needless complexity to the concepts and ideas, and distracting from a potentially cleaner, more focused, pointed narrative.