From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH kvm-unit-tests 2/4] Introduce a C++ wrapper for the kvm APIs Date: Thu, 25 Nov 2010 18:32:09 +0200 Message-ID: <4CEE8F89.2030106@redhat.com> References: <1290595933-13122-1-git-send-email-avi@redhat.com> <1290595933-13122-3-git-send-email-avi@redhat.com> <4CED1CC6.20603@codemonkey.ws> <4CED2148.60005@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Marcelo Tosatti , kvm@vger.kernel.org To: Anthony Liguori Return-path: Received: from mx1.redhat.com ([209.132.183.28]:42106 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753270Ab0KYQcN (ORCPT ); Thu, 25 Nov 2010 11:32:13 -0500 In-Reply-To: <4CED2148.60005@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On 11/24/2010 04:29 PM, Avi Kivity wrote: >>> +kvm_msrs* vcpu::alloc_msr_list(size_t nmsrs) >>> +{ >>> + size_t size = sizeof(kvm_msrs) + sizeof(kvm_msr_entry) * nmsrs; >>> + kvm_msrs* ret = static_cast(malloc(size)); >>> + if (!ret) { >>> + throw ENOMEM; >>> + } >>> + return ret; >>> +} >> >> malloc? >> >> Mixing C and C++ allocations is nasty stuff. Would be nicer to new >> an object and return it such that delete can be used consistently. > > 5 years of C. It has to be a malloc() in fact. We're allocating a variable size object that is not an array. You're right that we can't give it to an auto_ptr<> though, since that uses delete. -- error compiling committee.c: too many arguments to function