On 8/14/19 6:48 AM, Les Newell wrote:
I am working on a hal module that may need a variable amount of memory depending on it's configuration. Is it acceptable to use malloc in a hal module? Should I use hal_malloc or is that specifically for pins?

Memory management is different for realtime modules and non-realtime modules.

Non-realtime modules can do whatever they want, whenever they want.

Realtime modules have to go through two APIs to do memory management:

HAL pins & params must be allocated with the hal_*_new() functions. Those functions may be called only after a successful call to hal_init(), and before the call to hal_exit() . hal_exit() also automatically frees everything allocated with hal_*_new().

Normal (non-HAL) memory must be allocated with the rtapi_kmalloc() functions. Direct calls to malloc(), kmalloc(), mmap(), etc are not allowed.

The rtapi memory management functions are (barely) documented in the (confusingly named) "rtapi_slab" manpage:

http://linuxcnc.org/docs/2.7/html/man/man3/rtapi_slab.3rtapi.html

The rtapi memory management functions may only by called after a successful call to rtapi_init(), though note that hal_init() calls rtapi_init() for you. The memory allocated by rtapi_kmalloc() must be expliticly returned with rtapi_kfree().


--
Sebastian Kuzminsky


_______________________________________________
Emc-developers mailing list
Emc-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-developers

Reply via email to