Assing address to pointer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vlad

    #1

    Assing address to pointer

    In the following code:

    unsafe class X
    {
    byte* _address;
    void test()
    {
    _address=(byte* )144220152;
    }

    }

    Why the watch windows shows a differtent address for _address variable
    ?

  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Assing address to pointer

    Vlad,

    Are you sure you are not looking at the hexidecimal format for the
    number? Does it show you 8989FF8 instead (this is the same value in hex
    format)?

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Vlad" <a.sasanelli@gm ail.com> wrote in message
    news:1136819524 .606200.148700@ o13g2000cwo.goo glegroups.com.. .[color=blue]
    > In the following code:
    >
    > unsafe class X
    > {
    > byte* _address;
    > void test()
    > {
    > _address=(byte* )144220152;
    > }
    >
    > }
    >
    > Why the watch windows shows a differtent address for _address variable
    > ?
    >[/color]


    Comment

    • Vlad

      #3
      Re: Assing address to pointer

      Thanks for your help, but the problem isn't hexidecimal format

      Comment

      • Nicholas Paldino [.NET/C# MVP]

        #4
        Re: Assing address to pointer

        Vlad,

        Well, I changed the _address field and the test method to be public, and
        then wrote the value of _address out to the console after I ran test. The
        value was the same.

        There must be something else changing it which is not shown in the code
        that you posted.


        --
        - Nicholas Paldino [.NET/C# MVP]
        - mvp@spam.guard. caspershouse.co m

        "Vlad" <a.sasanelli@gm ail.com> wrote in message
        news:1136819524 .606200.148700@ o13g2000cwo.goo glegroups.com.. .[color=blue]
        > In the following code:
        >
        > unsafe class X
        > {
        > byte* _address;
        > void test()
        > {
        > _address=(byte* )144220152;
        > }
        >
        > }
        >
        > Why the watch windows shows a differtent address for _address variable
        > ?
        >[/color]


        Comment

        • Willy Denoyette [MVP]

          #5
          Re: Assing address to pointer


          "Vlad" <a.sasanelli@gm ail.com> wrote in message
          news:1136819524 .606200.148700@ o13g2000cwo.goo glegroups.com.. .
          | In the following code:
          |
          | unsafe class X
          | {
          | byte* _address;
          | void test()
          | {
          | _address=(byte* )144220152;
          | }
          |
          | }
          |
          | Why the watch windows shows a differtent address for _address variable
          | ?
          |

          _address is located on the stack and it's a pointer so the stack location
          will hold the value you set by _address=(byte* )144220152;
          To find the value of byte* you'll have to look at the contents of this
          location.

          Willy.


          Comment

          • Vlad

            #6
            Re: Assing address to pointer

            I change the question: What is the largest address that I can assign
            to pointer ?

            Comment

            • Vlad

              #7
              Re: Assing address to pointer

              I know, I'm interested at the address of pointer rather the value

              Comment

              • Willy Denoyette [MVP]

                #8
                Re: Assing address to pointer


                "Vlad" <a.sasanelli@gm ail.com> wrote in message
                news:1136887745 .168673.264020@ o13g2000cwo.goo glegroups.com.. .
                |I know, I'm interested at the address of pointer rather the value
                |

                What do you mean by that?

                _address is a variable located on the stack, you set the contents of this
                location to 144220152 by this assignment:

                _address=(byte* )144220152; // set _address to 0x08989ff8

                So suppose your _address is at 0x00125604; after the assignment, the int
                value at 0x00125604 will contain 0x08989ff8.
                Note that the value will be DWORD swapped, so the debugger will show
                0xf89f9808.

                Willy.






                Comment

                • Willy Denoyette [MVP]

                  #9
                  Re: Assing address to pointer


                  "Vlad" <a.sasanelli@gm ail.com> wrote in message
                  news:1136887569 .023453.272160@ g44g2000cwa.goo glegroups.com.. .
                  |I change the question: What is the largest address that I can assign
                  | to pointer ?
                  |

                  The largest user address on 32 bit windows is 0x7fffffff (decimal
                  2147483647), note that while you can point to anything between 0 and
                  0x7fffffff in your address space, it does not mean that read or write
                  from/to anything. What exactly are you trying to achieve.

                  Willy.


                  Comment

                  • Vlad

                    #10
                    Re: Assing address to pointer


                    Thanks for your patience this is the last post in the thread
                    It's wrong think that the following code in c# are equivalent?


                    byte* p;
                    p=someAddress

                    ----------------------------------------------------
                    IntPtr p=new IntPtr(someAddr ess)


                    The pointers are address container?

                    Comment

                    • Willy Denoyette [MVP]

                      #11
                      Re: Assing address to pointer


                      "Vlad" <a.sasanelli@gm ail.com> wrote in message
                      news:1136911662 .660437.284370@ g43g2000cwa.goo glegroups.com.. .
                      |
                      | Thanks for your patience this is the last post in the thread
                      | It's wrong think that the following code in c# are equivalent?
                      |
                      |
                      | byte* p;
                      | p=someAddress
                      |
                      | ----------------------------------------------------
                      | IntPtr p=new IntPtr(someAddr ess)
                      |
                      |
                      | The pointers are address container?
                      |

                      More or less;
                      case1: p is a variable that holds a pointer that points to a byte.
                      case2: p is a variable that holds a pointer to a void type.

                      Willy.


                      Comment

                      Working...