memory addressing

This is a discussion on memory addressing within the C Programming forums, part of the General Programming Boards category; I am having some partitioned pages using malloc function. The malloc function will return a address to the variable. I ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    39

    memory addressing

    I am having some partitioned pages using malloc function. The malloc function will return a address to the variable. I have to assign a address value to this partitioned pages. I will assign a function to theses pages. so whatever the value return in that function will be stored in that address.

    can anyone help me in this issue..

    thanks in advance...

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I don't understand what you mean by:
    I have to assign a address value to this partitioned pages.
    You already HAVE an address - that is what malloc() returns.

    I will assign a function to theses pages.
    What does this mean, each page will have a function?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    39
    i want to allocate pages of some KB which starts from address what i am giving.. one function, for eg: add function will be assigning to these pages. so the return value should be stored in that particular page which starts from the address wt i am giving.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I still don't understand what you want to do...

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Feb 2008
    Posts
    39
    i want to allocate 1MB of memory and partition those memory into pages, each of 4KB. Then i want to store the value returned by add function to one of the page allocated. I want the initial address to be given by the user and every time the function has to store the value in the same address. can i do it.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If by "initial address", you mean where in memory you should start your 1MB block, then malloc() does not allow this. There are OS specific functions that allow you to allocate memory at a specific address range [subject to that address range being available of course]. In linux/Unix, you'd use mmap(), in Windows VirtualAlloc().

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Feb 2008
    Posts
    39
    thanks matsp

  8. #8
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Ask malloc() to give you 1MB of memory. Then you can do whatever you want with it, such as creating a pointer to every 4KB in that 1MB block...

    Code:
    char* ptr_pool[256];
    char* buf = malloc( 1024 * 1024 );
    
    for ( int i = 0; i < 256; ++i )
    {
        ptr_pool[i] = buf + (i * 4096);
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. available memory from task manager
    By George2 in forum Tech Board
    Replies: 10
    Last Post: 01-18-2008, 02:32 AM
  2. Replies: 4
    Last Post: 01-13-2008, 02:14 AM
  3. Question regarding Memory Leak
    By clegs in forum C++ Programming
    Replies: 29
    Last Post: 12-07-2007, 01:57 AM
  4. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  5. Shared Memory - shmget questions
    By hendler in forum C Programming
    Replies: 1
    Last Post: 11-29-2005, 02:15 AM

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