Results 1 to 3 of 3

Thread: What do pointer values actually represent?

  1. #1
    Join Date
    Jan 2010
    Location
    Perth, Australia
    Posts
    37
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default What do pointer values actually represent?

    Hi all,

    When debugging or experimenting with low-level code, I sometimes examine pointer values like this:
    Qt Code:
    1. printf("Pointer points to %p\n", (void*)myPtr);
    To copy to clipboard, switch view to plain text mode 

    Usually, I'm only interested in confirming that two pointers have the same values, confirming that two pointers have different values, or finding the "positional differences" between pointer values. Thus, I've never needed to understand what the absolute values of those pointers are.

    However, I'm now curious as to what those values actually represent... If I get the message "Pointer points to 006CBAC0", does 006CBAC0 refer to a unique location in RAM? If two different, simultaneously-running processes attempt to dereference 006CBAC0, will they read the same physical location?

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: What do pointer values actually represent?

    It's a location in virtual RAM. Every process has it's own virtual memory. No process can access another processes data without ask the OS first and knowing the other processes process ID.

    The OS keeps and manages a virtual to physical mapping table. Some data (such as runtime libraries) may be loaded in memory once and shared amongst several processes. The processes themselves will have no knowledge of this (and the virtual memory locations may be different in each process)

    All the above is hardware accelerated by the CPU (ie, the virtual to physical lookups are done in hardware).

  3. The following user says thank you to squidge for this useful post:

    hackerNovitiate (27th February 2011)

  4. #3
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: What do pointer values actually represent?

    If two different, simultaneously-running processes attempt to dereference 006CBAC0, will they read the same physical location?
    As squidge said, each process is given it's own "virtual" memory - from the process point of view it looks like its the only process in the system, having all the available memory to itself.
    So, 006CBAC0 in one process will reference different physical memory location in another. Even if it was the same location, process can't access the memory which it does not own (without ask the OS first), trying to do so causes segmentation fault.

  5. The following user says thank you to stampede for this useful post:

    hackerNovitiate (27th February 2011)

Similar Threads

  1. Replies: 1
    Last Post: 4th December 2010, 17:20
  2. Represent a bit vector
    By danilodsp in forum Newbie
    Replies: 3
    Last Post: 20th October 2010, 16:10
  3. represent svg in tab view
    By Dilshad in forum Newbie
    Replies: 5
    Last Post: 27th July 2010, 09:47
  4. Getting the values from xml file
    By Kokos in forum Newbie
    Replies: 1
    Last Post: 6th April 2010, 10:32
  5. how to represent a graph?
    By harakiri in forum Qt Programming
    Replies: 2
    Last Post: 4th August 2009, 14:37

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.