public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
From: <tomas@tuxteam.de>
To: Peng Yu <pengyu.ut@gmail.com>
Cc: libc-help <libc-help@sourceware.org>
Subject: Re: What is the point of IPC_PRIVATE of shmget?
Date: Mon, 12 Apr 2021 18:06:39 +0200	[thread overview]
Message-ID: <20210412160639.GG1799@tuxteam.de> (raw)
In-Reply-To: <CABrM6w=oBUEcrWHTc-Q_ksoxwpHYCeLZnz0F+jG9bbeKMSrGoA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 904 bytes --]

On Mon, Apr 12, 2021 at 10:54:20AM -0500, Peng Yu via Libc-help wrote:
> Hi,
> 
> 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?
> 
> 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

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

  reply	other threads:[~2021-04-12 16:06 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-12 15:54 Peng Yu
2021-04-12 16:06 ` tomas [this message]
2021-04-12 16:07 ` Florian Weimer
2021-04-12 16:12   ` Peng Yu
2021-04-12 16:14     ` Florian Weimer
2021-04-12 16:18       ` Florian Weimer
2021-04-12 17:23       ` Peng Yu
2021-04-12 18:17         ` J Lumby
2021-04-12 17:55       ` Manfred
2021-04-12 19:05         ` Peng Yu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210412160639.GG1799@tuxteam.de \
    --to=tomas@tuxteam.de \
    --cc=libc-help@sourceware.org \
    --cc=pengyu.ut@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).