unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Marius Vollmer <mvo@zagadka.de>
Cc: guile-devel@gnu.org
Subject: Re: memory management
Date: 18 Mar 2003 20:48:50 +0100	[thread overview]
Message-ID: <8765qgzc9p.fsf@zagadka.ping.de> (raw)
In-Reply-To: <Pine.LNX.4.44.0303181910080.4168-100000@bono.reversers.net>

stefan <stefan@lkcc.org> writes:

>  > The memory is allocated by the libc @code{malloc} function and can be
>  > freed with @code{free}.  There is no @code{scm_free} function to go
>  > with @code{scm_malloc} to make it easier to pass memory back and forth
>  > between different modules.
> 
> Can you plese explain what "make it easier to pass memory back and forth
> between different modules" means?  What are modules in this context?

`Modules' is meant to mean different, errm, 'code regimes', like
libraries from different projects or developers.  These different
bodies of code have not necessarily been specifically written to work
together, but supposedly, they all use libc for their basic memory
management.

> Wouldn't it be more othogonal to supply a scm_free()?

Yeah, but we would force people to always pair scm_malloc with
scm_free.  (Offering scm_free without forcing people to use it would
have no effect.)  When they can't use scm_free because they have no
control over the code doing the freeing, they consequently can't use
scm_malloc although it might have been the right thing.  By not
insisting on scm_free, we make scm_malloc more useful.

> [...] On Win32 systems there is not such a thing like a standard
> libc.  There are different APIs around, especially regarding memory
> management.  When you use e.g. gh_scm2newstr() from an application
> linked against libguile.dll (which was ported using the msvcrt.dll -
> one of the libc's) and the calling application is linked against
> another libc (e.g.  kernel32.dll only) which provides 'another'
> free() as the msvcrt.dll... it fails!  This is bad I know, but not
> to work around...

This sounds like a very fundamental problem and I frankly don't want
to be drawn into the maelstrom of trying to fix it.  Next thing you
know, you can't pass a FILE* around, either!

When you step back one level, you have the problem that memory
allocated with "malloc" can not be freed with "free" when the memory
crosses a 'libc border'.  The only real solution that I can see is not
to mix more than one libc into a single program.

> Would you supply a scm_free() inside libguile.dll there would be no
> problem, because then the free() called inside libguile.dll:scm_free()
> would match the previous malloc() (also called inside libguile.dll).

If you can instruct code to use libguile.dll:scm_free instead of
kernel32.dll:free, can't you also instruct it to use msvcrt.dll:free
instead of kernel32.dll:free?

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405

  reply	other threads:[~2003-03-18 19:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-18 18:29 memory management stefan
2003-03-18 19:48 ` Marius Vollmer [this message]
2003-03-19 20:47   ` [dev-serveez] " stefan
2003-03-22 23:53     ` Marius Vollmer

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

  List information: https://www.gnu.org/software/guile/

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

  git send-email \
    --in-reply-to=8765qgzc9p.fsf@zagadka.ping.de \
    --to=mvo@zagadka.de \
    --cc=guile-devel@gnu.org \
    /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).