All of lore.kernel.org
 help / color / mirror / Atom feed
From: Philippe Gerum <rpm@xenomai.org>
To: Jan Kiszka <kiszka@domain.hid>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-help] native heap services and overloading new
Date: Thu, 03 Aug 2006 19:13:52 +0200	[thread overview]
Message-ID: <1154625233.5010.111.camel@domain.hid> (raw)
In-Reply-To: <44D0F876.8020406@domain.hid>

On Wed, 2006-08-02 at 21:09 +0200, Jan Kiszka wrote:
> Brandt Erickson wrote:
> > I have some code where I'd like to be able to dynamically allocate memory
> > in realtime.  Since the code is written in C++, I was thinking of just
> > making a huge global RT_HEAP and overloading the new and delete operators
> > to use the rt_heap_alloc and rt_heap_free functions.  First off, I'm
> > wondering if there are any caveats to this sort of thing that wouldn't be
> > obvious to someone new to xenomai like myself.  Second, if I fail to call
> > rt_heap_delete before the program terminates, does the heap remain
> > registered hang potentially causing problems when I try to re-allocate the
> > heap when the program is run again?  Thanks.
> 
> For now: yes, the heap will stay, no automatic cleanup (the posix skin
> already have this). You could then run into naming conflicts and you
> lose memory, of course.
> 
> But you could install some signal handler for cleaning up. We do so in
> our native-skin-based framework (also C++, but no "evil" ;) features in
> use). We even catch SIGSEGV this way.
> 

Another simple option: the binding operation is particularly useful for
recycling/discarding lingering objects.

RT_HEAP app_heap;

void init_heap (void)
{
	RT_HEAP old_heap;

	if (rt_heap_bind(&old_heap, "foo", TM_NONBLOCK) == 0)
		rt_heap_delete(&old_heap);

	rt_heap_create(&app_heap, "foo", ...);
}

-- 
Philippe.




      reply	other threads:[~2006-08-03 17:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-01 18:25 [Xenomai-help] native heap services and overloading new Brandt Erickson
2006-08-02 19:09 ` Jan Kiszka
2006-08-03 17:13   ` Philippe Gerum [this message]

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=1154625233.5010.111.camel@domain.hid \
    --to=rpm@xenomai.org \
    --cc=kiszka@domain.hid \
    --cc=xenomai@xenomai.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.