Thread: Pointer Qn, in windows only.

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    88

    Smile Pointer Qn, in windows only.

    Code:
    int *p = new int;
    p = 0x123;
    "p" is now pointing at
    (the 123*2 th byte of the memory of my program) or
    (the 123*2 th byte of the whole memory) ??

    /*====================================*/

    and if i want to change another process's memory ,
    how to do ? ( MFC or API )

    /*====================================*/

    THX.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    int *p = new int;
    p = 0x123;


    That is incorrect. There is no need to allocate that integer. Try:

    int *p = 0x123;

    or

    int *p = (int*)0x123;

    And I believe the address would be relative to the program's workspace. Anyway, protected-mode OS's like Windows won't let you enter an address space outside of the process you're in (in theory, at least. I once traversed my entire hard-drive with a far pointer. The catch was, I couldn't dereference the pointer without a seg-fault, but I could index through it with impunity(But then, how useful is that?). ).
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Each running process is allocated a 4GB virtual address address space.........When you use a pointer in usermode (be it from C++, Pascal,ASM,....whatever) you can access any memory location in this 4GB address space.....but many locations will throw access violations if you try to access them.

    It is possible to change other process's memory without shifting into kernelmode.......you can do stuff like forcing a process to load a dll of your making....or you can use WriteProcessMemory.....its not a very nice thing to do normally though

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    88
    thx twos.

    Originally posted by Fordy
    Each running process is allocated a 4GB virtual address address space.........When you use a pointer in usermode (be it from C++, Pascal,ASM,....whatever) you can access any memory location in this 4GB address space.....but many locations will throw access violations if you try to access them.

    It is possible to change other process's memory without shifting into kernelmode.......you can do stuff like forcing a process to load a dll of your making....or you can use WriteProcessMemory.....its not a very nice thing to do normally though
    ->if the 4GB's is used up , what will happen??

    ->and if there is 4GB for every process, much of the 4GB's memory may be waste, will the OS optimize about this ??

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by L.O.K.
    thx twos.



    ->if the 4GB's is used up , what will happen??

    ->and if there is 4GB for every process, much of the 4GB's memory may be waste, will the OS optimize about this ??
    That 4GB is theoretical......you dont use it all.......what is actively running is in RAM......what needs memory, but is not being used is paged to disk......and what is not used simply not committed

  6. #6
    Registered User
    Join Date
    Sep 2002
    Posts
    88
    Originally posted by Fordy
    That 4GB is theoretical......you dont use it all.......what is actively running is in RAM......what needs memory, but is not being used is paged to disk......and what is not used simply not committed
    ok , got .

  7. #7
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    That 4 GB comes from the fact that a pointer is ususally 4 bytes. At 8 binary bits per byte that's 2^32 different byte locations that you can address in a 4 byte pointer.

    That's

    4294967296 Bytes

    which is 4194304 Kilobytes

    which is 4096 Megabytes

    which is 4 Gigabytes worth of bytes that you can address.

    If you need to address more than 4 Gigabytes of memory and you are limited to a 4 byte pointer, then you have to do a bit of extra work to access those locations.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quick Pointer Question
    By gwarf420 in forum C Programming
    Replies: 15
    Last Post: 06-01-2008, 03:47 PM
  2. Script errors - bool unrecognized and struct issues
    By ulillillia in forum Windows Programming
    Replies: 10
    Last Post: 12-18-2006, 04:44 AM
  3. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM
  4. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM