CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Memory access

  1. #1
    Join Date
    Nov 2001
    Posts
    3

    Memory access

    Its a simple problem but I am having problems with accessing the (physical) memory. The problem i'm facing is as follows: I want to access the memory at a memory location (say 0x8000).The code i'm using for this purpose is as follows:

    unsigned int j;
    char xdata *w_ptr;

    j = 0x8000;
    w_ptr = (char *)j; // I want the pointer to point to memory location 0x8000.

    *w_ptr = data; // then transfer some bytes of data in the memory location




    I want to whether in the above code, does the pointer w_ptr really point to the desired location (in this case: 0x8000) ?

    Some1 please help me out, Thankyou in advance.


  2. #2
    Join Date
    Jul 2001
    Location
    Mumbai,India
    Posts
    382

    Re: Memory access

    Yes the pointer does indeed point to the memory location 0x00008000, but it is illegal to assign a pointer an address in this manner.
    If you try to write to that memory location it may result in a memory access violation.

    Regards,
    The Beret.


  3. #3
    Join Date
    Oct 2000
    Location
    London, England
    Posts
    4,773

    Re: Memory access

    Indeed - I remember years ago when we used to do this on purpose though in old MS-DOS applications.

    We would write to the screen memory location because it was a lot faster than using regular printf and cursor-location functions.

    In addition, it even used 2-byte characters - one of the bytes was used for attributes - foreground and background colour (3 bits each) with one bit for brightness (foreground only) and one for "flashing".

    I'm talking about back in 1988-1990 computers were much slower back then and the time-saving was essential!



  4. #4
    Join Date
    Sep 1999
    Location
    NJ
    Posts
    1,299

    Re: Memory access

    That works, but you seem to be going to a lot of extra effort:char* w_ptr = (char*) 0x00008000;
    char data = 0x55;
    *w_ptr = data;





    Truth,
    James
    http://www.NJTheater.com
    http://www.NovelTheory.com
    I don't do it for the points (OK, maybe I do), but rating a post is a good way for me to know if I helped.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured