Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!mit-eddie!genrad!panda!enmasse!drilex!axiom!linus!philabs!rdin!perl From: perl@rdin.UUCP (Robert Perlberg) Newsgroups: comp.lang.c Subject: Re: C structs & A question about octet Message-ID: <589@rdin.UUCP> Date: Thu, 13-Nov-86 12:51:38 EST Article-I.D.: rdin.589 Posted: Thu Nov 13 12:51:38 1986 Date-Received: Sun, 16-Nov-86 01:16:07 EST References: <2904@rsch.WISC.EDU> <8943@sun.uucp> Organization: Resource Dynamics Inc., New York Lines: 18 > head = (three_bytes*)calloc(N, sizeof(three_bytes)); > > This wastes N bytes. It still would even if sizeof(three_bytes)==3. Malloc allocates storage that is properly aligned for any data type. Therefore, even if you passed 3 instead of 4, malloc would still skip to the next big boundary. I suppose that someone could write a calloc that would align optimally based on the size of the data item being calloc'd, but how would it know just from the sizeof argument what the proper alignment for the data type should be? As far as I know, most, if not all, implementations of calloc just multiply their arguments and invoke malloc to allocate the storage. Robert Perlberg Resource Dynamics Inc. New York {philabs|delftcc}!rdin!perl