I have a C project that I'm using with Alchemy. The project has some post-build command-line tests that I'd like to run using the swfbridge.
These tests run, but they're extremely slow. The problem is that they read some moderately large files (~3MB) into memory. Running these same tests with the same files via regular Alchemy (e.g., not using swfbridge but using supplyFile from AS) is very fast.
I think the bottleneck is the swfbridge. More specicially, in the way that swfbridge loads files. It reads them in and transmits them in 1024 byte chunks across the localhost connection to the main alchemy swf. (You can see this happening in the swfbridge.log.)
My question is: is there a way to make swfbridge more efficient? Can I make it use a different chunk size, for example?
Here is an example of the file-reading code. If you give this code a ~3MB file it will run very slowly.
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
size_t filesize(const char filename[]) {
struct stat stbuf;
if (stat(filename, &stbuf) == -1) {
fprintf(stdout, "file_size: can't find %s\n...\n", filename);
return (-1);
}
return stbuf.st_size;
}
int main(int argc, char **argv) {
const char *filename= argv[1];
size_t size= filesize(filename);
printf("allocating %d bytes \n", size); fflush(stdout);
char *data= (char*)malloc(size);
printf("reading %d bytes \n", size); fflush(stdout);
FILE *file= fopen(filename, "r");
fread(data, size, 1, file);
printf("done \n"); fflush(stdout);
free(data);
fclose(file);
return 0;
}