# >>Each process, with their own stack, will they have their own heap or is it global one(common for all process)?
# if local,
# Any Limit on heap size like stack?
#
# if global,
# what if u dont free()?
Alot depends on what a 'process' is. On something like Unix, each process
has its own address space that cannot be easily modified by any other process.
On something Macintosh System 7 processes clobberring other processes's
memory is a frequent problem. So this depends on the underlying system and
cannot be answerred definitively.
There is some limit to heap size because machines have finite address space
and finite real memory and finite disc space. How much of those fundamental
limitations you can exploit depends on your system.
Resource scavenging on process exit depends on the system: some do,
some don't.
# How heap is initialized and maintained?? (any reference/link for
# heap/stack maintenace)
If you use the stdlib.h functions like malloc and free, the heap is
automagically initialised and maintained for you. Pay no attention to
the library behind the curtain.
# WORDSIZE:
#
# >> what is the relation between sizeof(int) in C and wordsize of an
# OS?(will it be 4 bytes, if u run gcc now in older OSs like WIN95 (16
# bit)..)
Usually they are the same. Whether they are two bytes or four or eight
or something else varies system by system. The situation is confusing
because the computer world is in flux between 32 and 64 bit words
and 8 and 16 bit characters.
# MALLOC:
#
#
# >> (this one lasted for 40 mins..) Consider following sample..
#
# char *arr=malloc(50) ;
#
# it is not guarenteed that memory for 'arr' will be contigous.. and
# when you use
The addresses you use are consecutive. Whether that is mapped into
noncontiguous physical addresses somewhere underneath is not the concern
of the C program; any such mapping must be invisible to your code such
that
# for(i=0;i<50;i+ +) {.. arr[i++]; ... }
works the same on all platforms.
If you do something like
typedef struct {char a,b,c;} abc;
abc *arr = malloc(50*sizeo f(abc));
arr might be allocated 150 or 200 (or elsewise) bytes. The compiler is
allowed to pad out the struct to a more convenient boundary, perhaps
adding one more invisible of char. Each array element is at consecutive
indexes, arr[0], arr[1], arr[2], ..., arr[49], but doesn't mean all
150 chars are contiguous.
That means if you want do something like zeroing out the array, you
should use sizeof
memset(arr,0,50 *sizeof(abc))
instead of trying to outguess the compiler
memset(arr,0,15 0)
--
SM Ryan
http://www.rawbw.com/~wyrmwif/
The whole world's against us.