Evangelista said:
i should have formulated my question this way :
in term of size in memory does these two solutions have the same effects? [slightly edited -- bad-practice cast removed, for instance]
int array[10]; /* vs */
int *array = malloc(sizeof(int) * 10);
In this case, the second version will consume an extra sizeof(int*) bytes.
It would probably be better to say that the second version
uses *at least* an extra sizeof(int *) bytes, provided that
the malloc() call succeeds.
In particular, a "real life" malloc() will need some sort of
auxiliary storage to record outstanding allocations and/or existing
free areas in some sort of "memory arena". This space may be
adjacent to, or distant from, the memory blocks handed back by
calls to malloc(), but it will occupy some sort of "overhead" space.
The amount of overhead varies from one implementation to another,
and for small allocations and certain types of allocators found
more often in Lisp implementations than in C ones, the actual
overhead for small areas such as "10 ints' worth of memory" might
only be a few bits, in effect, because they might track allocations
by addresses, mapping certain addresses to particular "bucket
sizes". More typically, there will probably be one or more
"void *" pointers and perhaps some additional overhead per handed-out
block, so that asking for 20 or 40 bytes requires as much as 32 or
64 bytes. If sizeof(int) is 4 and sizeof(int *) is 8, this might
then use 64+8 = 72 bytes total, vs only 40 bytes for the array.
Of course, as long as the result is correct, a compiler *is* allowed
to use something like Divine Guidance to avoid any extra overhead.
It just is not very likely.
