hardbinding a memory address to a variable in code

This is a discussion on hardbinding a memory address to a variable in code within the C Programming forums, part of the General Programming Boards category; How i can define a memory location for a variable. Here i mean i directly want to hardbind physical memory ...

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    22

    hardbinding a memory address to a variable in code

    How i can define a memory location for a variable. Here i mean i directly want to hardbind physical memory location in memory ,say x, for that variable or file? I mean i want to reserve some memory for that code and i want to hard bind to some pointer.

    What precautions i should take while doing so? How i could avoid conflict over that memory use? i mean how i will notify memory allocator not to assign it to some one.

    this is to avoid penalty occured while malloc and free.

    nitin

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,669
    > this is to avoid penalty occured while malloc and free.
    What penalty?

    Attempting to store a variable in a specific hardcoded memory location is a bad idea even if you pull it off, because your program may not have access to it. Leave it up to the OS to decide where your program belongs in memory and use malloc and free.

  3. #3
    Registered User
    Join Date
    Jul 2006
    Posts
    22

    atleast for knowledge sake

    i am not aware first at all how to do it. So atleast for this reason i want to do it.

    Here i talked on penalty in the sense of use of cpu by malloc and free

  4. #4
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,669
    > Here i talked on penalty in the sense of use of cpu by malloc and free
    If the world suddenly has to worry about the "strain" malloc and free put on the CPU, unix probably doesn't work anymore. The CPU cycles spent on allocating and deallocating memory are nothing to worry about compared to what your program is actually doing in terms of performance.

    I'm going to actually reference an article written by Prelude, so you can read that. She uses code that, as long as you have the same hardware she does, should store a value in a particular memory location. You should take an approach that does the same thing and fulfills your needs, but this is pretty hackish. Aside from the fact that Prelude is never wrong, it goes against standard portable code. So your computer could explode at any rate. Sorry.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers
    By xixpsychoxix in forum C Programming
    Replies: 4
    Last Post: 10-02-2008, 03:31 PM
  2. Finding memory address using memory pattern
    By MindWorX in forum C++ Programming
    Replies: 1
    Last Post: 05-25-2008, 07:20 AM
  3. DX - CreateDevice - D3DERR_INVALIDCALL
    By Tonto in forum Game Programming
    Replies: 3
    Last Post: 12-01-2006, 06:17 PM
  4. Memory address
    By Coder87C in forum Windows Programming
    Replies: 1
    Last Post: 03-03-2004, 01:55 AM
  5. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 01:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21