Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site umcp-cs.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!umcp-cs!chris From: chris@umcp-cs.UUCP (Chris Torek) Newsgroups: net.unix,net.lang.c Subject: Re: Portablity using structures and malloc - Help Message-ID: <928@umcp-cs.UUCP> Date: Sat, 20-Jul-85 23:31:41 EDT Article-I.D.: umcp-cs.928 Posted: Sat Jul 20 23:31:41 1985 Date-Received: Mon, 22-Jul-85 03:57:31 EDT References: <81@drux1.UUCP> <907@umcp-cs.UUCP> <4772@allegra.UUCP> Organization: U of Maryland, Computer Science Dept., College Park, MD Lines: 27 Xref: linus net.unix:4505 net.lang.c:5180 > malloc knows [the alignment constraints of the machine], but it's > a pity that you can't make malloc tell. If there were a nice > > int malign() {return ALIGNMENT_MULTIPLE;} True. However, there is a general rule you can use that I've not yet seen fail on any machine: align your object on an ``n'' bit boundary, where ``n'' is the smallest power of 2 that is not less than the size of the object you're allocating. (Of course this can be quite wasteful for large areas....) In case what I wrote doesn't say what I really meant, here's an example: int malign(size) register int size; { register int n = 0; while ((1 << n) < size) n++; return (1 << n); } -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251) UUCP: seismo!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@maryland