#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Posts
    205
    Rep Power
    0

    Question 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?
  2. #2
  3. No Profile Picture
    Offensive Member
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    Location
    in the perfect world
    Posts
    622
    Rep Power
    28
    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.

    Frank Zappa
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Seattle WA
    Posts
    863
    Rep Power
    14
    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.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Posts
    205
    Rep Power
    0
    Thanx to you people... Now i understood...

IMN logo majestic logo threadwatch logo seochat tools logo