get size of malloc'd object

Daniel R. Levy levy at ttrdc.UUCP
Sun Jun 29 08:47:37 AEST 1986


In article <9894 at ucsfcgl.ucsfcgl.UUCP>, arnold at ucsfcgl.UUCP writes:

>In article <2081 at umcp-cs.UUCP> chris at umcp-cs.UUCP (Chris Torek) writes:
>So put the int at the end of the space, after increasing the size
>to be allocated by sizeof (int) + enough space to align the int
>on a byte which is a multiple of sizeof (int).  Then return the
>original malloc()ed pointer.
>
>Can we say "hack"?
>
>		Ken Arnold

Now tell me please, how is one supposed to get at the int containing the
size later on (only knowing the pointer)?  You have to know the size
in order to calculate the offset to reach the size data!  Hardly sounds useful
(that's why the other suggestions have been to PREpend the size data, so its
location is known, though details have to be ironed out which has been fueling
much of the debate).



More information about the Comp.unix mailing list