I am trying to download large files to an Imp at the same time as processing other data, and I have very little free memory to play with.
I am downloading files in 5kb chunks by using
agent.on(). I want to download as fast as possible, and I’ve noticed that the vast majority of the download time is spent waiting for messages to travel between the device and agent, so I’m hoping to increase the size of my download buffer. Currently, after some time downloading, I am crashing with an out of memory error. My most recent logs before that indicate that I have around 10kb free memory, so I think that the problem is that I don’t have 5kb of contiguous memory to allocate to the blob as it comes into the callback for
I have a few questions about this:
Can you tell me any more about how the memory allocation works for data sent through
agent.on()? I imagine that the OS loads the data into some sort of network buffer, and then attempts to copy this over into a squirrel object.
Is there any way for me manually allocate the space for the data that the
agent.on()callback receives? So if I allocate a 5kb buffer at boot, and I know the data received will be 5kb, is there any way I can make sure that the data goes directly into the existing buffer without allocating more memory?
When I call
datais a 5kb blob. Are there any potential pros and cons to making
dataan array of multiple smaller blobs? The idea would be that, e.g., if
datawas an array of 5 1kb blobs, then the device could have an easier time allocating memory for 5 1kb blobs then for 1 5kb blob, due to contiguity issues.
Any other tips for increasing download speed on the Imp would be appreciated,