From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.tuxteam.de (mail.tuxteam.de [5.199.139.25]) by sourceware.org (Postfix) with ESMTPS id 2766E3844040 for ; Mon, 12 Apr 2021 16:06:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2766E3844040 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tuxteam.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tomas@tuxteam.de DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tuxteam.de; s=mail; h=From:In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:Date; bh=fpT1K9J7vMvqDvKalVwlvYn7h7CYQ3p5PNVQGQFjS60=; b=S2EDco69sUxYaApGwI9XDA8v4TF0E9miTZU7x5H5a1uK1jjrSo10UXQC1aIG2pk4uz5QLYDM68nk6JsmmiftsJcY02rthbGt0nUb0gEN+gOQh3IzyGOMMAGAIYgn/eGzDjifOGde3V0AovC4Wvh/yZDexFmDwP2xzbGD+m3qfPYonjXs9nxtRw/5STQcBTp/AP54trW7MBkr+Tl65f7ritxCQdkzq0UxyTxTzXjRW1Y+uq9EvEhKYW+FRUQVLFEZ3YfEj8ms4kGWsJ9i41S72yfY7kqGXslsb9elxlXHx7OB4wwyw+Q+wCmGHAmr5p13BzGUI+x/hBuVP7Pz6bV2SQ==; Received: from tomas by mail.tuxteam.de with local (Exim 4.80) (envelope-from ) id 1lVz5D-0002ay-OD; Mon, 12 Apr 2021 18:06:39 +0200 Date: Mon, 12 Apr 2021 18:06:39 +0200 To: Peng Yu Cc: libc-help Subject: Re: What is the point of IPC_PRIVATE of shmget? Message-ID: <20210412160639.GG1799@tuxteam.de> References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="/9ZOS6odDaRI+0hI" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) From: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-help@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-help mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Apr 2021 16:06:42 -0000 --/9ZOS6odDaRI+0hI Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Apr 12, 2021 at 10:54:20AM -0500, Peng Yu via Libc-help wrote: > Hi, >=20 > I don't get the point of IPC_PRIVATE of shmget(). Since it is just > used by the current process, why not just use malloc? >=20 > Can anybody give a real example in which IPC_PRIVATE must be used, but > malloc or other variant of *alloc functions are not appropriate to > use? Thanks. Typically you get a big chunk of memory via some cousin of shmget (it is, as far as I know, rather mmap or sbrk) and you deal out small pieces of it via malloc ("big" and "small" here are somewhat flexible terms). With an allocator like malloc you don't want to incur the cost of a system call. See the mallopt(3) man page to get a rough idea on how to tune the interplay of malloc and the underlying "big chunk" [1] provider. Cheers [1] Such a big chunk is often called "arena" in allocator parlance. -- t --/9ZOS6odDaRI+0hI Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEUEARECAAYFAmB0cA8ACgkQBcgs9XrR2kbfbwCeNqq3atXKM4FuDerIjxnA28pu g7cAliRpnx2htKVfsUq6luF9EIMIf6s= =f1XM -----END PGP SIGNATURE----- --/9ZOS6odDaRI+0hI--