Starbeamrainbowlabs

Stardust
Blog


Archive


Mailing List Articles Atom Feed Comments Atom Feed Twitter Reddit Facebook

Tag Cloud

3d 3d printing account algorithms android announcement architecture archives arduino artificial intelligence artix assembly async audio automation backups bash batch blog bookmarklet booting bug hunting c sharp c++ challenge chrome os code codepen coding conundrums coding conundrums evolved command line compilers compiling compression css dailyprogrammer data analysis debugging demystification distributed computing documentation downtime electronics email embedded systems encryption es6 features ethics event experiment external first impressions future game github github gist gitlab graphics hardware hardware meetup holiday holidays html html5 html5 canvas infrastructure interfaces internet interoperability io.js jabber jam javascript js bin labs learning library linux lora low level lua maintenance manjaro network networking nibriboard node.js operating systems own your code performance photos php pixelbot portable privacy problem solving programming problems project projects prolog protocol protocols pseudo 3d python reddit redis reference releases resource review rust searching secrets security series list server software sorting source code control statistics storage svg talks technical terminal textures thoughts three thing game three.js tool tutorial twitter ubuntu university update updates upgrade version control virtual reality virtualisation visual web website windows windows 10 xmpp xslt

Static Variable Memory Allocation

Recently we were asked in an Advanced Programming lecture to write a program that proves that static variables in C++ are located in a different area of memory to normal variables. This post is about the program I came up with.

But first I should probably explain a little bit about memory allocation in C++. I'm by no means an expert (I'm just learning!), but I'll do my best.

There are two main areas of memory in C++ - the stack and the heap. The stack is an ordered collection of data that contains all the local variables that you define. It grows downward from a given address in memory. The stack is split up into frames, too, with each frame being a specific context of execution. You can find more information about this in the Intel Software Developer's Manual, Section 6.2.

The second area of memory is the heap. The heap is a large portion of memory that can be used for storing large lumps of unordered data. I haven't taken a look at this yet, so I don't know much more about it.

Apparently variables that are declared to be static are not located in the stack (where they are located I'm not entirely sure), and we were asked to prove it. Here's what I came up with:

#include <iostream>
#include <string>

using namespace std;

void staticTest()
{
    static int staticD = 0;
    cout << "staticD: " << &staticD << endl;
}

int main()
{
    int a = 50;
    int b = 200;
    int c = 23495;

    cout << "a: " << &a << endl;
    cout << "b: " << &b << endl;
    cout << "c: " << &c << endl;

    staticTest();

    int e = 23487;
    cout << "e: " << &e << endl;

    //cin.get();

    return 0;
}

The above simply creates 3 normal variables, outputs their addresses, calls the staticTest() function to create a static variable and output it's memory address, and then creates a 4th normal variable and outputs its address too. The above program should output something like this:

a: 0091F8C4 b: 0091F8B8 c: 0091F8AC staticD: 00080320 e: 0091F8A0

In the above output, the normal variables a, b, c, and e are all located next to each other in memory between the adresses 0091F8C4 and 0091F8A0 (note how the memory address is decreasing - the stack grows downward, like a stalactite). The static variable staticD, however, is located in an entirely different area of memory over at 00080320. Since it's located in an entirely different area of memory, it's safe to assume, I think, that static variables are not stored in the stack, but somewhere else (I'm not sure where - the heap maybe?).

If you know where they are stored, please leave a comment below!

Programming 2 Coursework - PickupTheCrew

A screenshot PickupTheCrew I recently got an email from a university friend asking for my Programming 2 coursework. It gave me the idea that I should make a blog post about it, so here it is. For my Programming 2 coursework this seester I was asked to build a game to a specification called "Pickup The Crew". My implementation can be found below:

I am releasing this under the CC-BY-SA (Creative Commons Attribution Share-Alike) license. If this is not the correct license for this thing, please contact me (leave a message in the comments!) and I will change it.

You can find it here: PickUpTheCrew

To extract the above archive you will need 7-zip. Once extracted navigate to PickupTheCrew\PickupTheCrew\bin\Windows\Release and double click PickupTheCrew.exe.

If you have any problems, please comment below and I will try to help.

Rob Miles' Tags for Red Nose Day

The tags that I bought

Hello again!

Rob Miles sold these unique 3D printed tags generated by a python program for red nose day for £1 each. I bought 4. If you had a tag that was identical to a picture that he showed on the board in his Lecture in Rhyme (which was great by the way), then you won either a Remote control Car or a Robot. Needless to say I didn't win, but I did have a great time :)

Thing list for 3 Thing Game!

The thing list for 3 thing game has just been released!

Find it here.

In case you can't read the list there, the list is as follows:

Tower, Beaver, Brain, Seagull, plane, Polo, Wombat, Harmonica, Pastie, Spam Fritter, Waifu, Shop, Pasta, Apocalypse, Pirate, Haunted, Really large gun, Struggle, Tentacles, Elephant, MLG, Skeleton, Parrot, Mayhem, Heist, Mountain Dew, Rhythm, Wristwatch, Rubber, Cauldron, Jacket, Doritos, Puzzler, stealth, Cat, Kit-Kat, Crimping, Undersea, Grunting, Zeus, Flesh Eating, Spell, Cool Spot, Potato, Clock, Boiler Suit, Pineapple, Space, Ocean Liner, Robot, Boots, Alien, Rainbow, Frantic, Drainpipe, Pig, Puzzle, Mushroom, Dressing Up, Hand grenade, Gong, Ninja, Steroids, Potion, Dilemma, Zombie, Bones, Graveyard, planets, Cube, Wand, Electric, Warlock, Jellyfish , Vampire, German, Paint, Nerds, Circles, Bus, Tunnel, Cupcakes, System, Broomstick, Party, Lazer, Sci-Fi, Panic, Skull, Ethical, Voxel, Plot, Locked, Robotic, Pixies, Unity, Spacecraft, Inventor, kettle, Balloon, Topdown, Ghost, Satan, Nuke, Nose, University , Banjo, Fingers, petril, Panini, Green, Flying Fish, Banana, Gems, Anti-aircraft gun, Android, Falling, Snakes, Combat, Goat, instakill, Chickens, Communism, Tribal, of Doom, Downstairs, Wolf, Umbrella, Maggot, Ship, Time, Weapon, Football, wizard, Cheesebot, Hunting, Grave, Slippery, Endoscope, Meme, Cheese, Yeti, Bat, Beard, Trousers, Attack, Witch, Assassin, Pension, Pea, Web, Triangles, Spider

Art by Mythdael