flash - swfbridge and large files -


i have c project i'm using alchemy. project has post-build command-line tests i'd run using swfbridge.

these tests run, they're extremely slow. problem read moderately large files (~3mb) memory. running these same tests same files via regular alchemy (e.g., not using swfbridge using supplyfile as) fast.

i think bottleneck swfbridge. more specicially, in way swfbridge loads files. reads them in , transmits them in 1024 byte chunks across localhost connection main alchemy swf. (you can see happening in swfbridge.log.)

my question is: there way make swfbridge more efficient? can make use different chunk size, example?

here example of file-reading code. if give code ~3mb file 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; } 

i figured out workaround problem.

when running swf command line, file i/o slow because swf process getting file swfbridge process via localhost sockets. unoptimized (the alchemy guys didn't expect use in serious way). swfbridge used stdin , stdout work. i'm not clear on why used file i/o-- swf running in adl (air!) after all-- has file system access.

anyway, fact swf running in air can used. can route fread/fwrite through air methods (rather through swfbridge) using wonderful funopen. bit of code, here's idea of it:

file* air_fopen(const char filename[], const char mode[]) {     as3_val file= as3_filefrompath(filename);      as3_val filemodeclass= as3_getclass("flash.filesystem", "filemode");     as3_val filemode     = as3_gets(filemodeclass, fopenmodetoairmode(mode));      as3_val filestream   = as3_newobject("flash.filesystem", "filestream");      as3_callts("open", filestream, "as3valtype, as3valtype", file, filemode);      as3_release(filemodeclass);     as3_release(filemode);       as3_release(file);      return funopen(filestream,                    (funopen_read_t)air_fread, (funopen_write_t)air_fwrite,                    (funopen_seek_t)air_fseek, (funopen_close)air_fclose); }  

where air_read this:

int air_fread(as3_val filestream, char *dest, int size) {     int bytesavailable= as3_getintproperty(filestream, "bytesavailable");     if (bytesavailable <= 0) {         return 0;     } else if (size > bytesavailable) {         size= bytesavailable;     }      as3_callts("readbytes", filestream, "as3valtype, inttype, inttype", as3_ram(), dest, size);      return size; } 

the other air_fwrite/air_fweek/air_fclose similar. note of these functions (like as3_filefrompath, as3_getinproperty, as3_newobject, etc) own simple wrappers around as3 api.

this approach removes swfbridge bottleneck , makes command-line swfs fast normal ones.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -