Question: I'm trying to make my very first game. Its a simple endless scroller 2D game build with Unity 4.3.4. and C#.

Everything works fine, but if you look closely, you can see it has tiny hiccups. When you look closely at the left, the particles not moving smooth at all.

What am i doing wrong? It looks like there is something wrong with the framerate or something.

Live version: <http://www.atticweb.nl/peekgame/> Download: <https://dl.dropboxusercontent.com/u/6929740/peekseek.rar>

---

Could it be i'm giving him forward motion with changing the velocity? :
rigidbody2D.velocity = new Vector2 ( speed, rigidbody2D.velocity.y )

Answer: 
EDIT: Thank you to [***Pascal***](https://stackoverflow.com/users/139746/pascal-cuoq) for his comment which is indeed correct! I have changed the answer as a result of this.

---

Using any optimization setting other than none, the compiler would optimize this function away *if it was statically defined* i.e., local to this compilation unit. With no optimizations turned on it might not. In that case the [***function prologue and epilogue***](http://en.wikipedia.org/wiki/Function_prologue), which are code that sets up the stack frame etc on entering the function, and destroys it on leaving, may still be emitted by the compiler.

As Pascal points out when it has external linkage this is not possible as the compiler doesn't generally "reach" across modules. However, in this case the linker should optimize it out if it detects that the function is not called.

Also it is completely possible to determine how much memory a function takes up. You can look at the [***elfdump***](http://www.unix.com/man-page/opensolaris/1/elfdump/)/[***objdump***](http://en.wikipedia.org/wiki/Objdump), or similarly appropriate utility, for the object that contains the function :)

---

To answer your question

> 
> If the function is called, then what is occupying the memory space? 
> 
> 
> 

A function must be compiled into [***machine code***](http://en.wikipedia.org/wiki/Machine_code). This is a set of instructions of architecture-dependent length/value etc that reside in memory. The computer fetches instructions from memory. Therefore your function must reside somewhere in memory for the CPU to be able to fetch it and then execute it. The C code your write is compiled into this machine code and it is this that takes up memory space...
If we ignore that the compiler may or may not optimize the function away, then there are many different kinds of memory occupied by a function.

Each time a function is called, it is likely that the program has to store away various CPU registers on the stack, registers such as the [status/condition code register](http://en.wikipedia.org/wiki/Status_register). Also, the program counter will be stored on the stack, or the CPU wouldn't know where to return to, once the function is done executing. 

What kind of registers that are saved, and where, and how, depends on the system. The CPU likely does a lot of this automatically, upon encountering an "execute function" instruction in the program.

If there are any parameters or return values, they will also be stored on the stack/in registers. In that case, they may be saved by the caller or by the function, it is system specific and known as [calling convention](http://en.wikipedia.org/wiki/Calling_convention).

In addition to the above, the actual code that is the body of the function is of course stored somewhere too: in the program memory (often referred to as `.text`).