Here's a snippet of my code:
Code: Select all
char doneHeader = 0;
int recvd_len;
char incoming_buffer[BUFFER_SIZE];
int dataIn = 0;
while((recvd_len = recv(my_socket, incoming_buffer, BUFFER_SIZE, 0)) != 0) {
if(recvd_len > 0) {
int contentLength = recvd_len;
char *contentBuffer = incoming_buffer;
if(!doneHeader) {
contentLength -= getDataStart(incoming_buffer) - incoming_buffer;
contentBuffer = getDataStart(incoming_buffer);
doneHeader = 1;
}
FILE *o = fopen(localFilename, "ab");
fwrite(contentBuffer, contentLength, 1, o);
fclose(o);
dataIn += BUFFER_SIZE;
printf("%d / 1,424,880\n", dataIn);
}
}
iprintf("Done!\n");
The problem is, my DS outputs this:
1024 / 1,424,880
2048 / 1,424,880
...
105472 / 1,424,880
And then freezes.
My guess is that the DS is running out of RAM because dswifi isn't freeing the data that I've already written to the file and don't need anymore.
So how can I get dswifi to download the file in chunks, freeing up memory once it has been delt with?