Advertisement

Pointers arise again!

Started by December 29, 2002 12:45 AM
5 comments, last by Tazel 21 years, 10 months ago
So are the purpose of pointers are to be able to handle big data easily? It also helps deal and munipulate it also. Any other purposes thought of would be appreciated if they were posted here. Thanks! tcache Contact Me ----------- Games don''t affect kids. If Pac-man had affected us, we''d all be sitting in darkened rooms munching pills and listening to repetitive electronic music. -- Kristian Wilson(Nintendo Inc., 1989)
tcacheContact Me-----------AH! MY BRAIN IS GOING TO SELF-DETONATE! -- Yours Truly (Jan, 2003)
Well, Im no master on pointers to say the least, but there was a good article on them posted here a few weeks ago. It brings up some of the uses of pointers:

http://www.gamedev.net/reference/articles/article1869.asp
------------------------Why of course the people don’t want war. ... That is understood. But after all it is the leaders of the country who determine the policy, and it is always a simple matter to drag the people along, whether it is a democracy, or a fascist dictatorship, or a parliament, or a communist dictatorship ...Voice or no voice, the people can always be brought to the bidding of the leaders. That is easy. All you have to do is to tell them they are being attacked, and denounce the pacifists for lack of patriotism and exposing the country to danger. It works the same in any country. [Herman Goering]
Advertisement
Pointers are useful because they allow access to the freestore.

Putting things on the freestore have an advantage because they can be used in more than 1 function.

Sure you can use global variables to do the same thing but that is really unsafe. So putting data on the freestore is more safer.

Also there is a lot more freestore memory than normal memories that data for variables for stored. So you can declare more array elements and variables on the freestore.

So here''s an example.

local variable
int x;//declared on the STACK not freestore. So the variable
cannot be used in any other function other than the function it was declared in or if it is a global variable.

pointer to put data on the free store.
int *x=new int;

There this data can now be access in any function as long as you keep the address to the freestore memory that the pointer X points to.

Also pointers allow you to NOT predict how much memory you might need to store for arrays. Because you can add new memory and delete them according to the actions of the users. This is used mainly for linked lists and you can conserve memory.

Oh yeah and another thing. Poitners are also used for VIRTUAL FUNCTIONS AND POLYMORPHISM. A very useful Object Oriented technique.
A pointer is just an alias for an address in memory. It has nothing to do with "big data." You can use pointers to allocate memory on the freestore (or more commonly called heap) like the above poster said. You can also use pointers to pass data around efficiently. And pointers can also be used to do low level memory accesses, if you were doing system level code for example. There is nothing magical about pointers, but all you have to know about them is that a pointer simply holds a memory address. You can learn more from there. I suggest you read "C++ Pointers and Dynamic Memory Management" by Michael Daconta. He explains it beautifully.
They are also used for linked lists...anything else?


tcache
Contact Me
-----------
Games don''t affect kids. If Pac-man had affected us, we''d all be sitting in darkened rooms munching pills and
listening to repetitive electronic music. -- Kristian Wilson(Nintendo Inc., 1989)
tcacheContact Me-----------AH! MY BRAIN IS GOING TO SELF-DETONATE! -- Yours Truly (Jan, 2003)
Advertisement
C-style strings:
char *String = "C-style string!\n\n";
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________

This topic is closed to new replies.

Advertisement