Jump to content
The Lotus Eaters: Share Bug Reports and Feedback Here! ×

Anyone Good With Pointers?


Nosebleed
 Share

Recommended Posts

I'm currently taking a Computer Science class with C++ as the class language.  I'm having trouble wrapping my head around this concept because I just can't find a good use for them.

 

I heard it is indispensable to use in games such as Warframe.  Can anyone explain to me the use of pointers in Warframe or any other game?

If it helps, I have more experience with coding in JavaScript.  Whereas if I had multiple things containing a similar variable, I would just create a new object with that similar variable as a property.

Link to comment
Share on other sites

I'm taking one with C, so it should be familiar.

 

Pointers are useful because they contain an address to a value. So basically, they point at stuff. The reason they are useful is because in C/C++, arguments are passed by value. In other words, functions are given copies of stuff instead of the actual stuff. Using pointers allows you to modify variables in functions, which is EXTREMELY handy when you get to complex data structures such linked lists. Pointers can also be used to dynamically allocate memory (only giving things the exact amount of memory it needs). This means they can be used to handle almost unlimited amounts of data on the fly. 

Link to comment
Share on other sites

You should try Google.  Maybe something like this:

 

<http://www.c-for-dummies.com/caio/pointer-cheatsheet.php>

 

Pointers are a key abstraction.  Like Algebra.  It takes some people a bit of time to make it click.  Pointers are a reference / address / token to something else.  For example, your house has an address (or geolocation).  The location isn't your house, but your house is at that location.  If you go to the location, you get your house.  The house is the thing, but the pointer is its address.

 

I'd recommend starting with C.  C++ is needlessly complicated and you can work up to it with C99.

Link to comment
Share on other sites

I'm a student too, but I think I understand. You're saying that if you have 3 objects with a 'stats' array, you would create a 4th statholder to house it, and have the other 3 call getstats() from the 4th object when needed, or something to that effect.

 

Games like warframe have to be VERY efficient when it comes to performance. There's alot of stuff a computer does behind the scenes when it calls a method, and much less with a pointer.

 

Calling getstats() requires the process to stop running whatever it's doing, push data to the stack, go to the getstats method of the statholder class, get the info it needs, then return that, unpack from the stack, then keep doing what it was doing before. This is (from a computer perspective) very time consuming.

 

By contrast, a pointer is a direct memory reference. Following that pointer to memory is just like reading out of an array, a constant time operation. It doesn't get any faster. Additionally, changing it does not require calling a setstats() method, you just update the pointer (by which I mean the thing the pointer is pointing to).

 

That's why you use pointers, and [one reason] why c++ is the preferred gaming language. They are also used in polymorphism http://www.learncpp.com/cpp-tutorial/121-pointers-and-references-to-the-base-class-of-derived-objects/)

 

 

I'd recommend starting with C. C++ is needlessly complicated and you can work up to it with C99.

Not an option for him, it's the required language for his class.

 

 

i'm good at pointing my middle finger at someone

USER!

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...