Flash Gordon wrote:[color=blue]
> jacob navia wrote:
>[color=green]
>>
ganesh.kundapur@gmail.com a écrit :
>>[color=darkred]
>>> Hi,
>>> Is there any way to get the total heap size allocated to a process
>>> in c on linux platform.
>>>
>>> Regards,
>>> Ganesh
>>>[/color]
>>
>> This could give you an approximation:
>>
>> #include <stdio.h>
>> #include <stdlib.h>
>>
>> int main(void)
>> {
>> unsigned int size=1;
>> unsigned int *p = &size;
>>
>> while (p) {
>> p = malloc(size);
>> if (p) {
>> free(p);
>> size *= 2;
>> }
>> }
>> printf("Stopped at size=%u\n",size);
>> }[/color]
>
>
> That does not tell you how much memory is allocated to the heap on any
> system I've used recently since they increase the amount of memory
> allocated to the heap as more requests are made. It *might* tell you the
> largest power of two block you can allocate, or if the system is less
> than optimal it might fail much earlier than that due to memory
> fragmentation. There are lots of other problems with your suggestion
> that are specific to Linux systems and so off topic here.
>
> The correct advice of asking on a Linux group had already been given.[/color]
Yes, I misunderstood the question. Actually the OP wanted to know the
heap size of a running process, and I understood that he wanted to know
the maximum heap size for a process.
Sorry for the confusion.
jacob