January 5th, 2003, 10:51 AM
Why we have to use pointers in memory allocation???
What is the idea of using pointers in memory allocation? I mean why we have to use pointers?
January 5th, 2003, 11:59 PM
Think of the memory block as being your home.
Think of the pointer to the memory as your address or phone number.
Next time you need someone to come round to your house, try doing it without telling them the address.
Or try to send them a copy of your home.
The pointer is returned after a successful memory allocation.
It is the START of the memory block. It allows the SAME return value for all memory allocations irregadless of size, function used alloc /realloc /GlobalAlloc /new /far /calloc ect or data type.
The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.
January 6th, 2003, 02:14 AM
Pointers are very useful. Once you get a handle on them, you'll realize they're pretty much everywhere, in every language, whether or not you handle them directly.
They allow you to defeat scope. Data can be initialized in one scope, and used in another. This may sound bad at first, but in has its uses, and often is needed. Without this, you need to use extensive use of globals, which is generally considered sloppy.
Similarly, they allow data to be exchanged across applications. You can't pass a variable from one app to another, since the second app doesn't have any concept of the first app's variables. Tell second app though where the data is (a pointer), and it can read it just fine. Exchanging data across apps isn't something you're likely to do at first, but today's software does it extensively. Take a look someday at all the different ActiveX, OLE, or COM controls installed on a recent Windows station: all of these work by one application hosting another and exchanging data.
Pointers allow structures/classes that wouldn't be possible with only member variables. Look into linked lists, or any type of node structure. They would lose alot of their functionality if they're forced to contain all data as member variables.
The list goes on.
January 6th, 2003, 06:11 AM
Thanx to you people... Now i understood...