tobold.org

correct • elegant • free

△ Comp.lang.c △

◅ What is the reason so many coders don't check return values ?

Q: Nested includes good or bad? ▻

Free() memory??

[ I'm sending this thread back to comp.unix.programmer, where it belongs. ]

In article <8icmep$87r$1@nnrp1.deja.com>,  <dimitrio@my-deja.com> wrote:
>In article <u0snue9kds.fsf@hana.kurims.kyoto-u.ac.jp>,
>  Matthias Blume <see@my.sig> wrote:
>> Many Unices have mmap.  Use mmap (with file /dev/zero) to allocate
>> memory in lange chunks, manage these chunks yourself, and munmap them
>> once you don't need the space anymore.
>
>Yes, you will probably have to manage the memory yourself, but there is
>a better and more straightforward way of doing this: having #included
><unistd.h> you'll be able to use
>
>    void *sbrk(size_t)

Why do you say sbrk() is better?

I can see a major problem with using sbrk() to do your own memory
management: you will interfere with any library routines, such as
malloc(), that use sbrk().  Specifically, between allocating your memory
and releasing it again, you must ensure that there are no other calls to
sbrk().

With mmap(), there is no such problem: you can munmap() exactly the
memory you obtained, and there is no danger of interaction with anything
else.

Tim.
--
Tim Goodwin   | "Not ideal, I grant you, but life's
Leicester, UK | like that." -- Ian Batten

Original headers:

From: tjg@star.le.ac.uk (Tim Goodwin)
Newsgroups: comp.lang.c,comp.unix.programmer
Subject: Re: Free() memory??
Followup-To: comp.unix.programmer
Date: 16 Jun 2000 11:37:30 +0100
Message-ID: <8id020$1ha$1@ltpcg.star.le.ac.uk>
References: <8icf7v$2cc$1@nnrp1.deja.com>
  <u0snue9kds.fsf@hana.kurims.kyoto-u.ac.jp> <8icmep$87r$1@nnrp1.deja.com>

△ Comp.lang.c △

◅ What is the reason so many coders don't check return values ?

Q: Nested includes good or bad? ▻