Thread: memory partition

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

    memory partition

    How can i do partition pf the memory like partition0 has 50kbytes, partition1 has next 50 kbytes like that.. how can i do using C programming.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    What do you actually 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.

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    39
    i want to do partition in the space available in memory into some 3 or 4 partitions, whose size will be 50 kbytes each...

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    1. Develop a data structure, such as a linked list:
    Code:
    struct block {
       void * mem;
       size_t memlen;
       struct block * mem;
    ];
    2. Allocate the block sizes you need.

    Success. RAM has been partitioned enough to suit your needs, and organized so that you may access it. Malloc can actually give you more than you ask for (I imagine that most implementations of malloc like to employ a simpler scheme, like fragmenting memory at word boundaries or at byte sizes that are powers of two).

  5. #5
    uint64_t...think positive xuftugulus's Avatar
    Join Date
    Feb 2008
    Location
    Pacem
    Posts
    355
    Quote Originally Posted by citizen View Post
    1. Develop a data structure, such as a linked list:
    Code:
    struct block {
       void * mem;
       size_t memlen;
       struct block * mem;
    };
    I am pretty sure you made a small typo in the code.
    Code:
    struct block {
       void * mem;
       size_t memlen;
       struct block * next_block;
    };
    Code:
    ...
        goto johny_walker_red_label;
    johny_walker_blue_label: exit(-149$);
    johny_walker_red_label : exit( -22$);
    A typical example of ...cheap programming practices.

  6. #6
    Registered User
    Join Date
    Feb 2008
    Posts
    39
    can i allocate using malooc function?

  7. #7
    Registered User
    Join Date
    Feb 2008
    Posts
    39
    sorry "malloc" function...

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I'm still not sure what you want to do, but yes, you should be able to allocate blocks of 50KB at a time with malloc.

    Partition to me means that there is some sort of "wall" between the memory blocks, enforced by hardware preferably, which the above solution doesn't provide.

    --
    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.

  9. #9
    uint64_t...think positive xuftugulus's Avatar
    Join Date
    Feb 2008
    Location
    Pacem
    Posts
    355
    You can allocate using any function designed for that purpose.
    malloc: Allocate but not initialize
    use:
    Code:
    #include <stdlib.h>
    ...
    void *mem;
    mem = malloc(1024);  /* 1024 bytes uninitialized */
    calloc: Allocate and set to zero sized objects.
    use:
    Code:
    #include <stdlib.h>
    
    struct foo {
       int bar;
       char foobar[64];
    };
    
    int main()
    {
        struct foo *lot_of_foo;
        lot_of_foo = calloc(sizeof(struct foo), 100); /* 100 foo's, and their memory 0 */
    }
    Code:
    ...
        goto johny_walker_red_label;
    johny_walker_blue_label: exit(-149$);
    johny_walker_red_label : exit( -22$);
    A typical example of ...cheap programming practices.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with insert/delete binary search tree
    By Nazgulled in forum C Programming
    Replies: 39
    Last Post: 03-25-2009, 04:24 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Suggestions on this C style code
    By Joelito in forum C Programming
    Replies: 11
    Last Post: 06-07-2007, 03:22 AM
  4. Shared Memory - shmget questions
    By hendler in forum C Programming
    Replies: 1
    Last Post: 11-29-2005, 02:15 AM
  5. hardware interaction in c
    By vineetwadwekar in forum C Programming
    Replies: 6
    Last Post: 03-29-2002, 09:01 AM