J
Joris Adriaenssens
This is my first posting, please excuse me if it is off-topic.
I'm learning to program in C. It's been almost ten years I've been
programming and a lot of things have changed apparently.
I understand from other postings that casting a result from malloc
isn't good. In the past I have always been casting the malloc. I
think it was even necessary. (But that's a long time ago, I hadn't
heard of a standard for C these days). Was it really necessary or did
we do it only to silence the warnings ? (cfr. FAQ q7.7 - I can't
look in the manuals from these days : I don't have them any longer)
When I use malloc for the allocation of a small piece of memory, e.g.
a single node of a linked list, I use 'free' to release the memory
afterwards. When using 'free', I don't have to worry about the size
of the allocated block the pointer is pointing to.
Is it the operating-system that is responsible to remember the size of
that piece of memory ?
In that case, when I build a large linked-list by allocating memory
for each node, I get a lot of overhead in the operating system. Is
this right ? or is this implementation-specific or operating-system
specific ? (FAQ q7.26 says that the implementation 'remembers' the
size. Does this mean that every implementation may do it in his own
way ? )
If the computer has to remember for each single allocation the size of
the allocated block, is it better than, to allocate a bigger piece of
memory and keep track of the use of it within the program, when I try
to create a linked-list or a binary tree or something like that ?
Thank you.
Joris Adriaenssens
I'm learning to program in C. It's been almost ten years I've been
programming and a lot of things have changed apparently.
I understand from other postings that casting a result from malloc
isn't good. In the past I have always been casting the malloc. I
think it was even necessary. (But that's a long time ago, I hadn't
heard of a standard for C these days). Was it really necessary or did
we do it only to silence the warnings ? (cfr. FAQ q7.7 - I can't
look in the manuals from these days : I don't have them any longer)
When I use malloc for the allocation of a small piece of memory, e.g.
a single node of a linked list, I use 'free' to release the memory
afterwards. When using 'free', I don't have to worry about the size
of the allocated block the pointer is pointing to.
Is it the operating-system that is responsible to remember the size of
that piece of memory ?
In that case, when I build a large linked-list by allocating memory
for each node, I get a lot of overhead in the operating system. Is
this right ? or is this implementation-specific or operating-system
specific ? (FAQ q7.26 says that the implementation 'remembers' the
size. Does this mean that every implementation may do it in his own
way ? )
If the computer has to remember for each single allocation the size of
the allocated block, is it better than, to allocate a bigger piece of
memory and keep track of the use of it within the program, when I try
to create a linked-list or a binary tree or something like that ?
Thank you.
Joris Adriaenssens