Mail Archives: djgpp/1995/04/02/09:22:23
Dear programmers,
I am a scientist that programs in C, and I am not sure about some
aspects concerning pointers. I have written my doubts as "assumptions"
I think they are true.
I'd like to know if they are really true and to get an answer for a
specific question I ask at the end of this message
Thank you in advance!
=========================================
ASSUMPTION 1. When some function allocates memory, this memory will not
be freed when the function returns. This implies:
a/ If the function does not free the memory block and does not return
the pointer, that memory block will be occupied until the program
stops, and there is no way to free it.
b/ If the function returns the pointer, it is possible to use it and
even to free it.
If these assumptions are true, I suppose:
ASSUMPTION 2. the Operating System always knows the size of an allocated
block simply by indicating the base address (when I call free() I simply
gives this argument), no matter if I am in the same funcion that
allocated the memory block or not.
If ASSUMPTION 2 is true, is there an ANSI-C manner to get from the O.S.
the amount of memory a pointer points to? I have tried "sizeof(pointer)",
but it only returns the size of a single element.
=========================================
I am not subscribed to the list, so I'd appreciate you answer directly
to in"%ibbt0 AT cc DOT uab DOT es".
Thank you!
Xavier Pons
- Raw text -