local_heap.c

00001 #include <native/heap.h>
00002 
00003 #define HEAP_SIZE (256*1024)
00004 #define HEAP_MODE 0             /* Local heap. */
00005 
00006 RT_HEAP heap_desc;
00007 
00008 int init_module (void)
00009 
00010 {
00011     void *block;
00012     int err;
00013 
00014     /* Create a 256Kb heap usable for dynamic memory allocation of
00015        variable-size blocks in kernel space. */
00016 
00017     err = rt_heap_create(&heap_desc,"MyHeapName",HEAP_SIZE,HEAP_MODE);
00018 
00019     if (err)
00020         fail();
00021 
00022     /* Request a 16-bytes block, asking for a non-blocking call since
00023        only Xenomai tasks may block. */
00024     err = rt_heap_alloc(&heap_desc,16,TM_NONBLOCK,&block);
00025 
00026     if (err)
00027         goto no_memory;
00028 
00029     /* Free the block: */
00030     rt_heap_free(&heap_desc,block);
00031    
00032     /* ... */
00033 }
00034 
00035 void cleanup_module (void)
00036 
00037 {
00038     rt_heap_delete(&heap_desc);
00039 }

Generated on Mon Mar 24 18:02:40 2008 for Xenomai API by  doxygen 1.5.3