Skip to contentSkip to conversation

Question about xnmalloc and xnheap_alloc

Xenomai ニャン星人 2 participants 2 messages Dec 5, 2015

lore
Share & tools
lore
#0 lore raw

Hi, I had read the source code of xenomai3.X. And I am curious about the difference between xnmalloc and xnheap_alloc. When using this two api, where the memory these api apply from. What do the variable cobalt_heap use for?

How can I achieve shared memory function by use these two api in kernel between xenomai and linux?

Thank you very much. I would appreciate your help.

#1 lore raw
Quoted 2 lines · ニャン星人

Hi, I had read the source code of xenomai3.X. And I am curious about the difference between xnmalloc and xnheap_alloc.

The answer is in xnmalloc definition:
#define xnmalloc(size) xnheap_alloc(&cobalt_heap, size)

Quoted 1 line

When using this two api, where the memory these api apply from.

The memory has been reserved prior to calling these functions, and an "xnheap" object initialized with the xnheap_init call.

Quoted 1 line

What do the variable cobalt_heap use for?

cobalt_heap is the "global heap" object. You can use memory from this heap object with xnmalloc, or use memory from another heap object (initialized with xnheap_init) with xnheap_alloc.

Quoted 4 lines

How can I achieve shared memory function by use these two api in kernel between xenomai and linux?

Any memory obtained with Linux memory allocation function is shared between Xenomai and Linux. The xnheap objects are just a way to pre-allocate some memory and allow a kind of dynamic allocation for real-time services without resorting to Linux services. But the memory you pass to an xnheap object (and in particular the cobalt_heap object memory) is generally some Linux memory that has been allocated in advance.

Signature · 2 lines
					    Gilles.
https://click-hack.org