malloc realloc and pointers



Hi all,

I m relatively new to C. I have few queries related to malloc():

1. When we perform malloc(), the memory allocated dynamically comes from
the heap area of the process in concern. Well, we then say that the heap
has shrinked. my query is: Is it that the heap physically does not
shrink but the perticular nodes are marked 'ALLOCATED' and for
subsequent calls to malloc() the memory manager remembers them and does
not reference them?

2. With realloc(), if some pointer 'ptr' is pointing initially to a
perticular position in a buffer (char *buffer) then on performing a
realloc() on this buffer, what will be 'ptr' pointing to?

3. whats the maximum memory size that we can allocate dynamically by
calling malloc() ?

4. Is it valid in C to typecast a pointer? eg. code snippet... of
course int is 16 bit and long is 32 bit.
int *variable, value;
*((long*)variable)++ = value;
*((long*)variable)++ = value;
*((long*)variable)++ = value;
*((long*)variable)++ = value;

thanx in advance

.



Relevant Pages

  • RE: Defeating Microsoft Windows XP SP2 Heap protection
    ... Fact is XP SP2 is still far less likely to be vulnerable to buffer overflow ... > than the memory buffer allocated to hold it. ... > the operating system is now more careful to reduce both stack and heap ... > Execution Protection ...
    (microsoft.public.windowsxp.general)
  • Re: malloc realloc and pointers
    ... When we perform malloc(), the memory allocated dynamically comes from ... the heap area of the process in concern. ... perticular position in a buffer then on performing a ...
    (comp.lang.c)
  • Re: stack and heap
    ... books explain that local stack variables for each function are automatically allocated when function starts and deallocated when it exits. ... malloc() always takes memory in the heap. ...
    (comp.programming)
  • malloc and realloc
    ... When we perform malloc(), the memory allocated dynamically comes ... from the heap area of the process in concern. ... perticular position in a buffer then on performing a ...
    (comp.lang.c)
  • Re: Understanding Linux addr space, malloc, and heap
    ... > I don't understand what is happening with malloc and the heap in my ... > chunk of memory that holds dynamically-allocated memory. ... the "heap" is still brk in linux, however there is no 1:1 relation ... between heap and malloc. ...
    (Linux-Kernel)