Re: where to use malloc() and calloc in controller programming
1. calloc allocates a block of memory for an array of elements of a certain size. By default the block is initialized to 0. The total number of memory allocated will be (number of elements * size).
2. malloc allocates memory blocks and returns a void pointer to the allocated space, or NULL if there is insufficient memory available.
calloc allocates an array in memory with elements initialized to 0 and returns a pointer to the allocated space.
malloc takes in only a single argument which is the memory required in bytes. malloc allocated bytes of memory and not blocks of memory like calloc.
IT DOES same kind of work in micro controllers also
Problem :- Using dynamic memory on PICs(MCU) with their very small RAM space is fraught with peril. You can rapidly run out of contiguous space due to the lack of more advanced virtual memory managers that full blown OS's give you, leading to failed allocations and crashes. Worse, it may not be deterministic, and will likely be a pain to debug.
To use this :- **broken link removed**