Xref: utzoo comp.lang.c:23310 comp.std.c:1955 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!cs.utexas.edu!uunet!ateng!chip From: chip@ateng.com (Chip Salzenberg) Newsgroups: comp.lang.c,comp.std.c Subject: Re: Another malloc question Message-ID: <254636D5.4455@ateng.com> Date: 25 Oct 89 22:42:28 GMT References: <428@cpsolv.UUCP> Organization: A T Engineering, Tampa, FL Lines: 21 According to rhg@cpsolv.UUCP (Richard H. Gumpertz): >Suppose a system has one data type "X" that must be aligned on a 32-byte >boundary, but all other objects can be aligned on a 2-byte boundary. >The current standard seems to prohibit malloc from special-casing requests >for less than size X and returning only even alignment. This feature serves a useful purpose. Suppose you have pointers to large structures, and you need more than one special pointer value. NULL isn't enough. You can get a properly aligned structure pointer by calling malloc(1); use this pointer as the magic cookie. You can't dereference such a pointer, but you can assign it and compare against it. Such a ploy can save you some memory, since you don't have to declare a static structure just to use its unique address as a magic cookie. [I hope that this strategy doesn't run afoul some obscure restriction...] -- You may redistribute this article only to those who may freely do likewise. Chip Salzenberg at A T Engineering; or "'Why do we post to Usenet?' Naturally, the answer is, 'To get a response.'" -- Brad "Flame Me" Templeton