Most old school formats have max size limits for good reasons, and the really good protocols allow the receiver to specify the maximum amount of data to send at a time!
Of course if your device has 256K of memory, reserving 64K for a max size TCP/IP packet is incredibly wasteful.
But if you can receive one of those packet at any time, realistically you need to have 64K available at any time so....
I'm not sure about newer stuff. Last time I did embedded things like Bluetooth were sectioned off into their own bit of memory, malloc was used, and it was a source of bugs that we weren't happy about.
Imagine my disappointment after working on a fixed-allocation HTTP server stack to discover that even `esp_log.h` does several malloc() calls [1] per log output line... thankfully that was only on the ESP8266_RTOS_SDK, and esp-idf isn't quite as bad.
Networking can use allocators other than malloc. You mostly need arbitrary allocation for stuff like packet payload which can be arbitrary size (within limits). Many other structures, like IP headers, etc, can use much simpler, faster, safer allocators.
I know LwIP is pretty good around that sort of thing. It was just a little bit of a shock to see a lot of usage of malloc throughout ESP-IDF. But then it does have to handle Wi-fi, Bluetooth and more. It runs well though! And it does somewhat amortise its use of malloc to setup functions where possible.
One of the challenges I’ve had in the firmware work we’ve been doing, is the sheer amount of network-received runtime configuration. Makes statically allocating everything difficult. Not impossible of course, but our memory usage ends up sky high because we end up allocating buffers for the 70% of code that isn’t even going to be executed! So using “dynamic” allocation once when the runtime config determines this functionality is actually needed has worked reasonably well
Though it really reminds me of avoiding the GC in garbage collected languages, which is a little amusing to think about
Except for things like the ESP32, which uses malloc pretty liberally within ESP-IDF. Networking is hard without it, it seems?