All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mads Martin Joergensen <mmj@mmj.dk>
To: mlmmj@mlmmj.org
Subject: Re: memory management in mlmmj
Date: Thu, 24 Mar 2005 00:38:44 +0000	[thread overview]
Message-ID: <20050324003844.GC67964@mmj.dk> (raw)
In-Reply-To: <20050323212830.GA21199@mopo.webdmz.tv2.dk>

* Morten K. Poulsen <morten@afdelingp.dk> [Mar 23. 2005 22:29]:
> Memory management makes up quite a large portion of the code, especially
> freeing memory at error conditions. How about we sacrifice a tiny bit of memory
> and performance and automate it?
> 
> The basic idea here is to have scopes of dynamic memory, a lot like local
> variables. At the beginning of each function we could begin a scope, and at the
> end of a function (and at returns) we could end it. If we need to return a
> pointer to some memory, we could move that chunk of memory up to the parent
> scope. I think that would work well, and make the code a lot more readable.
> 
> It is not new, I think PHP does something like this (where a request is the
> scope).
> 
> I have made a small proof of concept:
> http://www.afdelingp.dk/files/memory.c
> 
> MEM_BEGIN opens a new scope.
> MEM_END closes the current scope.
> MEM_SAVE(ptr) moves a chunk of memory to the parent scope.
> 
> mymalloc() and myfree() works as usual.
> 
> Is it a bad idea?

The idea is nice, but why start changing all this code that works
already with something that had no serious testing yet? There's so many
other places that could need some work before this.

Also we should have a look at:

 http://irccrew.org/~cras/security/c-guide.html and

and (from the dovecot imap server source):

 dovecot-0.99.14/src/lib/mempool*

before deciding on how to approach this. There's some really nice ideas
here as well.

-- 
Mads Martin Joergensen, http://mmj.dk
"Why make things difficult, when it is possible to make them cryptic
 and totally illogical, with just a little bit more effort?"
                                -- A. P. J.

  parent reply	other threads:[~2005-03-24  0:38 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-23 21:28 memory management in mlmmj Morten K. Poulsen
2005-03-23 22:44 ` Christian Laursen
2005-03-24  0:38 ` Mads Martin Joergensen [this message]
2005-03-24  8:04 ` Mads Toftum
2005-03-24  8:07 ` Mads Martin Joergensen
2005-03-24  8:11 ` Mads Toftum
2005-03-24  8:14 ` Mads Martin Joergensen
2005-03-29  9:24 ` Morten K. Poulsen

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=20050324003844.GC67964@mmj.dk \
    --to=mmj@mmj.dk \
    --cc=mlmmj@mlmmj.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.