All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] native heap services and overloading new
@ 2006-08-01 18:25 Brandt Erickson
  2006-08-02 19:09 ` Jan Kiszka
  0 siblings, 1 reply; 3+ messages in thread
From: Brandt Erickson @ 2006-08-01 18:25 UTC (permalink / raw)
  To: xenomai

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.
-Brandt



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Xenomai-help] native heap services and overloading new
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Kiszka @ 2006-08-02 19:09 UTC (permalink / raw)
  To: Brandt Erickson; +Cc: xenomai

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

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.

Jan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 250 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Xenomai-help] native heap services and overloading new
  2006-08-02 19:09 ` Jan Kiszka
@ 2006-08-03 17:13   ` Philippe Gerum
  0 siblings, 0 replies; 3+ messages in thread
From: Philippe Gerum @ 2006-08-03 17:13 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: xenomai

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.




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-08-03 17:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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.