Heap Size

Discussion in 'C Programming' started by Raman, Jun 22, 2007.

  1. Raman

    Raman Guest

    Hi All,


    Could any one tell me, how can I determine/Change size of heap on per-
    process basis on Unix based systems.


    Thanks.

    Regards
    Raman Chalotra
     
    Raman, Jun 22, 2007
    #1
    1. Advertising

  2. Raman <> writes:
    > Could any one tell me, how can I determine/Change size of heap on per-
    > process basis on Unix based systems.


    Try comp.unix.programmer.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Jun 22, 2007
    #2
    1. Advertising

  3. "Keith Thompson" <> schrieb im Newsbeitrag
    news:...
    > Raman <> writes:
    >> Could any one tell me, how can I determine/Change size of heap on per-
    >> process basis on Unix based systems.

    >
    > Try comp.unix.programmer.

    And/or check 'man ulimit'

    Bye, Jojo
     
    Joachim Schmitz, Jun 22, 2007
    #3
  4. Raman

    Army1987 Guest

    "Raman" <> ha scritto nel messaggio news:...
    > Hi All,
    >
    >
    > Could any one tell me, how can I determine/Change size of heap on per-
    > process basis on Unix based systems.


    If by "heap" you mean "memory available for dynamic allocation":

    #include <stdio.h>
    #include <stdlib.h>
    int main(void)
    {
    size_t size = 1;
    unsigned char *p = NULL;
    do {
    size *= 2;
    p = realloc(p, size);
    } while (p);
    printf("Heap size is less than %lu but more than %lu bytes.\n",
    (unsigned long)size, (unsigned long)size / 2);
    return 0;
    }

    But to change it you (if you can) would need system-specific ways.
    Try asking a newsgroup about Unix.
     
    Army1987, Jun 22, 2007
    #4
  5. Raman

    Richard Bos Guest

    "Army1987" <> wrote:

    > "Raman" <> ha scritto nel messaggio


    > > Could any one tell me, how can I determine/Change size of heap on per-
    > > process basis on Unix based systems.


    > If by "heap" you mean "memory available for dynamic allocation":
    >
    > #include <stdio.h>
    > #include <stdlib.h>
    > int main(void)
    > {
    > size_t size = 1;
    > unsigned char *p = NULL;
    > do {
    > size *= 2;
    > p = realloc(p, size);
    > } while (p);
    > printf("Heap size is less than %lu but more than %lu bytes.\n",
    > (unsigned long)size, (unsigned long)size / 2);
    > return 0;
    > }


    Do note that the message that is printed may, instead, be "This process
    has been terminated by the sysadmin because of runaway memory abuse.",
    and the second time you run it it may be "This account has been
    temporarily deactivated.NO CARRIER".

    IOW, please do not do this on a multi-user system.

    Richard
     
    Richard Bos, Jun 22, 2007
    #5
  6. Raman

    Army1987 Guest

    "Richard Bos" <> ha scritto nel messaggio news:4all.nl...
    > "Army1987" <> wrote:
    >
    >> "Raman" <> ha scritto nel messaggio

    >
    >> > Could any one tell me, how can I determine/Change size of heap on per-
    >> > process basis on Unix based systems.

    >
    >> If by "heap" you mean "memory available for dynamic allocation":
    >>
    >> #include <stdio.h>
    >> #include <stdlib.h>
    >> int main(void)
    >> {
    >> size_t size = 1;
    >> unsigned char *p = NULL;
    >> do {
    >> size *= 2;
    >> p = realloc(p, size);
    >> } while (p);
    >> printf("Heap size is less than %lu but more than %lu bytes.\n",
    >> (unsigned long)size, (unsigned long)size / 2);
    >> return 0;
    >> }

    >
    > Do note that the message that is printed may, instead, be "This process
    > has been terminated by the sysadmin because of runaway memory abuse.",
    > and the second time you run it it may be "This account has been
    > temporarily deactivated.NO CARRIER".
    >
    > IOW, please do not do this on a multi-user system.


    Very fine point. I had temporarily forgotten what happened the last
    time I did something like while (1) { p = malloc(200); } on such a
    system.
    (Also, now I realized what happens if (SIZE_MAX + 1) / 2 bytes of
    memory can successfully allocated, and if realloc(p, 0) does not
    return a null pointer...)
     
    Army1987, Jun 22, 2007
    #6
  7. On Fri, 22 Jun 2007 12:29:22 +0200, "Army1987" <>
    wrote:

    >
    >"Raman" <> ha scritto nel messaggio news:...
    >> Hi All,
    >>
    >>
    >> Could any one tell me, how can I determine/Change size of heap on per-
    >> process basis on Unix based systems.

    >
    >If by "heap" you mean "memory available for dynamic allocation":
    >
    >#include <stdio.h>
    >#include <stdlib.h>
    >int main(void)
    >{
    > size_t size = 1;
    > unsigned char *p = NULL;
    > do {
    > size *= 2;
    > p = realloc(p, size);
    > } while (p);
    > printf("Heap size is less than %lu but more than %lu bytes.\n",
    > (unsigned long)size, (unsigned long)size / 2);
    > return 0;
    >}
    >



    This does not relate to the total amount available but to the largest
    contiguous block available and even then it could report a number much
    too low.


    Remove del for email
     
    Barry Schwarz, Jun 22, 2007
    #7
  8. >>>>> "Army" == Army1987 <> writes:

    Army> "Raman" <> ha scritto nel messaggio
    Army> news:...
    >> Hi All,
    >>
    >>
    >> Could any one tell me, how can I determine/Change size of heap
    >> on per- process basis on Unix based systems.


    Army> If by "heap" you mean "memory available for dynamic
    Army> allocation":

    Army> #include <stdio.h>
    Army> #include <stdlib.h>
    Army> int main(void)
    Army> {
    Army> size_t size = 1;
    Army> unsigned char *p = NULL;
    Army> do {
    Army> size *= 2;
    Army> p = realloc(p, size);
    Army> } while (p);
    Army> printf("Heap size is less than %lu but more than %lu
    Army> bytes.\n",
    Army> (unsigned long)size, (unsigned long)size / 2);
    Army> return 0;
    Army> }

    Army> But to change it you (if you can) would need system-specific
    Army> ways. Try asking a newsgroup about Unix.


    I don't think this does what the OP wants since realloc can (and on my
    system does) change the size of the heap when it needs to.

    <OT>
    The heap size can be changed on Unix systems, man sbrk.
    </OT>
     
    Dale Henderson, Jun 25, 2007
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sunny
    Replies:
    5
    Views:
    2,118
    CBFalconer
    Aug 17, 2006
  2. Michal Slocinski

    Heap dump file size vs heap size

    Michal Slocinski, Mar 25, 2008, in forum: Java
    Replies:
    1
    Views:
    738
    GArlington
    Mar 25, 2008
  3. Jason Cavett

    Preferred Size, Minimum Size, Size

    Jason Cavett, May 23, 2008, in forum: Java
    Replies:
    5
    Views:
    12,585
    Michael Jung
    May 25, 2008
  4. viki
    Replies:
    6
    Views:
    566
    Erik Wikström
    Jun 28, 2008
  5. Raymond Schanks
    Replies:
    0
    Views:
    533
    Raymond Schanks
    Apr 11, 2010
Loading...

Share This Page