From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 032B62C86B for ; Thu, 11 Oct 2018 03:59:07 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id l3sbbC_4rdCE for ; Thu, 11 Oct 2018 03:59:06 -0400 (EDT) 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 turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id B7E7F2C7C1 for ; Thu, 11 Oct 2018 03:59:06 -0400 (EDT) From: Kirill Shcherbatov Subject: [tarantool-patches] [PATCH v4 05/14] box: introduce tuple_format_sizeof routine Date: Thu, 11 Oct 2018 10:58:50 +0300 Message-Id: <95a45583991d6285ea53d2c8b9a24571d2c8a848.1539244271.git.kshcherbatov@tarantool.org> In-Reply-To: References: In-Reply-To: References: Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: vdavydov.dev@gmail.com, Kirill Shcherbatov New tuple_format_sizeof routine calculates the size of memory for tuple_format allocation. Part of #1012. --- src/box/tuple_format.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/box/tuple_format.c b/src/box/tuple_format.c index d8acaa5..6a287f2 100644 --- a/src/box/tuple_format.c +++ b/src/box/tuple_format.c @@ -42,6 +42,18 @@ static const struct tuple_field tuple_field_default = { }; /** + * Calculate the size of tuple format allocation. + * @param field_count Count of tuple fields. + * @retval Size of memory allocation. + */ +static inline uint32_t +tuple_format_sizeof(uint32_t field_count) +{ + return sizeof(struct tuple_format) + + field_count * sizeof(struct tuple_field); +} + +/** * Add and initialize a new key_part to format. * @param format Format to initialize. * @param fields Fields definition if any. @@ -225,8 +237,7 @@ tuple_format_alloc(struct key_def * const *keys, uint16_t key_count, } } uint32_t field_count = MAX(space_field_count, index_field_count); - uint32_t total = sizeof(struct tuple_format) + - field_count * sizeof(struct tuple_field); + uint32_t total = tuple_format_sizeof(field_count); struct tuple_format *format = (struct tuple_format *) malloc(total); if (format == NULL) { -- 2.7.4