question about pointers???

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tamara omar
    New Member
    • Sep 2006
    • 23

    question about pointers???

    is it possible to declare any array of constant pointers? why?
  • m013690
    New Member
    • Sep 2006
    • 23

    #2
    You CAN make just about anything a constant. But if you did that, you would have to initialize the pointers when you created them, and could never dynamically allocate more memory.

    This could be useful, though, because a pointer uses much less memory (potentially) than the object to which it points. That way, you could save yourself (potentially, again) A LOT of over head from passing arguments to functions.

    For instance, if you created a user-defined object that took up, say, 100 bytes of memory (maybe it's a class that contains 100 chars). To pass that to a function would require an entire copy of the class, and the time it took to create the copy.

    But, the pointer to the class, since it only contains an address, might be only 1 byte, or maybe 2, or 4, depending on the system. Either way, it's considerably smaller than 100, so it would (potentially) save your program processing time to be using only pointers instead of complete objects.

    Comment

    • D_C
      Contributor
      • Jun 2006
      • 293

      #3
      A constant pointer is a reference. If you had N references, then an array of N const pointers would work wonderfully.

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        In embedded applications we often use constant pointers to point at specific locations of hardware registers since these generally don't move during program execution.

        Comment

        Working...