From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id B32DF469710 for ; Thu, 4 Jun 2020 00:27:31 +0300 (MSK) From: Vladislav Shpilevoy References: Message-ID: <599b3e8d-cacd-b480-0a19-158fbac417f4@tarantool.org> Date: Wed, 3 Jun 2020 23:27:29 +0200 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [Tarantool-patches] [PATCH small 1/1] region: new region_alloc_array, updated alloc_object List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org, alyapunov@tarantool.org, tsafin@tarantool.org Still need 2 reviews here. On 21/05/2020 22:32, Vladislav Shpilevoy wrote: > Region's API provided a macro for aligned allocation of an object: > region_alloc_object(). But not less frequent there is a case when > need to allocate an array of objects, also aligned. The patch adds > region_alloc_array() for that. > > Also the patch adds an out parameter 'size' for both macros. It > simplifies total size calculation, which is needed almost always, > because total size is included into an error message, if the > allocation fails. > > Needed for https://github.com/tarantool/tarantool/issues/4609 > --- > Branch: http://github.com/tarantool/small/tree/gerold103/region_alloc_array > Issue: https://github.com/tarantool/tarantool/issues/4609 > > small/region.h | 15 ++++++++++----- > 1 file changed, 10 insertions(+), 5 deletions(-) > > diff --git a/small/region.h b/small/region.h > index bea88c6..df6567d 100644 > --- a/small/region.h > +++ b/small/region.h > @@ -386,10 +386,15 @@ struct RegionGuard { > }; > #endif /* __cplusplus */ > > -#define region_reserve_object(region, T) \ > - (T *)region_aligned_reserve((region), sizeof(T), alignof(T)) > - > -#define region_alloc_object(region, T) \ > - (T *)region_aligned_alloc((region), sizeof(T), alignof(T)) > +#define region_alloc_object(region, T, size) ({ \ > + *(size) = sizeof(T); \ > + (T *)region_aligned_alloc((region), sizeof(T), alignof(T)); \ > +}) > + > +#define region_alloc_array(region, T, count, size) ({ \ > + int _tmp_ = sizeof(T) * (count); \ > + *(size) = _tmp_; \ > + (T *)region_aligned_alloc((region), _tmp_, alignof(T)); \ > +}) > > #endif /* INCLUDES_TARANTOOL_SMALL_REGION_H */ >