By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,885 Members | 1,072 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,885 IT Pros & Developers. It's quick & easy.

Heap Size

P: n/a
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

Jun 22 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Raman <ra***********@gmail.comwrites:
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) ks***@mib.org <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"
Jun 22 '07 #2

P: n/a
"Keith Thompson" <ks***@mib.orgschrieb im Newsbeitrag
news:ln************@nuthaus.mib.org...
Raman <ra***********@gmail.comwrites:
>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
Jun 22 '07 #3

P: n/a

"Raman" <ra***********@gmail.comha scritto nel messaggio news:11*********************@o11g2000prd.googlegro ups.com...
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.
Jun 22 '07 #4

P: n/a
"Army1987" <pl********@for.itwrote:
"Raman" <ra***********@gmail.comha 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
Jun 22 '07 #5

P: n/a

"Richard Bos" <rl*@hoekstra-uitgeverij.nlha scritto nel messaggio news:46***************@news.xs4all.nl...
"Army1987" <pl********@for.itwrote:
>"Raman" <ra***********@gmail.comha 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...)
Jun 22 '07 #6

P: n/a
On Fri, 22 Jun 2007 12:29:22 +0200, "Army1987" <pl********@for.it>
wrote:
>
"Raman" <ra***********@gmail.comha scritto nel messaggio news:11*********************@o11g2000prd.googlegro ups.com...
>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
Jun 22 '07 #7

P: n/a
>>>>"Army" == Army1987 <pl********@for.itwrites:

Army"Raman" <ra***********@gmail.comha scritto nel messaggio
Armynews:11*********************@o11g2000prd.googl egroups.com...
>Hi All,
Could any one tell me, how can I determine/Change size of heap
on per- process basis on Unix based systems.
ArmyIf by "heap" you mean "memory available for dynamic
Armyallocation":

Army#include <stdio.h>
Army#include <stdlib.h>
Armyint 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}

ArmyBut to change it you (if you can) would need system-specific
Armyways. 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>
Jun 25 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.