> 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? > > Les
First choice: Memory may be dynamically allocated within real time by using local variables though even though it is technically possible to dynamically vary size I am uncertain if it is possible in C/C++ but think it is in ADA. I am uncertain if compiler always use stack memory which may be different from ordinary memory, in a Micro controller it is usually the same memory although at a different memory location. This method of dynamic memory allocation is my first choice for several reasons but is not always possible to use. Second choice: If amount of memory is known then progam is compiled an ordinary variable not local to a function is a good choice. This is second choice because variable is not local though it may still be as local as possible if needed in more than one function. Third choice: If the amount of memory is known from configuration, at initialization or similar memory could be allocated before real time is started and it should be OK. If memory is allocated from heap in a real time thread then it is really hard to guarantee it will always be available and to put an upper bound on execution. I would expect problems sometimes if memory is allocated in a thread executed at a frequeny of for example 1kHz. Nicklas Karlsson _______________________________________________ Emc-developers mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/emc-developers
