From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Wed, 1 Aug 2007 11:29:09 +0200 From: Adrian Bunk Subject: Re: [RFC PATCH] type safe allocator Message-ID: <20070801092909.GN3972@stusta.de> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Sender: owner-linux-mm@kvack.org Return-Path: To: Miklos Szeredi Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, torvalds@linux-foundation.org List-ID: On Wed, Aug 01, 2007 at 11:06:46AM +0200, Miklos Szeredi wrote: > I wonder why we don't have type safe object allocators a-la new() in > C++ or g_new() in glib? > > fooptr = k_new(struct foo, GFP_KERNEL); > > is nicer and more descriptive than > > fooptr = kmalloc(sizeof(*fooptr), GFP_KERNEL); >... But it's much more likely to break when someone converts fooptr to a different struct. It might not be a common case but it sometimes happens - and your type safe variant introduces the possibility for really nasty bugs. cu Adrian -- "Is there not promise of rain?" Ling Tan asked suddenly out of the darkness. There had been need of rain for many days. "Only a promise," Lao Er said. Pearl S. Buck - Dragon Seed -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org