String has some functions which let one pass in a buffer. I was  
thinking those could be quite nice to use with mmap or  
CreateFileMapping. Maybe Array could be given something similar. That  
would save you from doing a bunch of little memory-to-memory copies  
and probably some rather large copies from your address space into the  
kernel. I realize this doesn't help you immediately, but maybe it  
gives you something to lobby for and/or contribute.

Pete Gontier <http://pete.gontier.org/>



On Oct 13, 2008, at 11:01 AM, ondras wrote:

>
> Hi,
>
> I am wondering what is the most effective way of writing a JS binary
> string (array of numbers-bytes) into a file. My first attempt folows:
>
>        v8::Handle<v8::Array> arr =
> v8::Handle<v8::Array>::Cast(args[0]);
>        int len = arr->Length();
>
>        int max = 4096;
>        int current = 0;
>        char buf[max];
>        for (int i=0;i<len;i++) {
>            v8::Handle<v8::Integer> a = v8::Integer::New(arr-
>> Get(v8::Integer::New(i))->IntegerValue());
>            buf[current++] = (char) a->Int32Value();
>            if (current == max) {
>                fwrite(buf, sizeof(char), current, f);
>                current = 0;
>            }
>        }
>        if (current) { fwrite(buf, sizeof(char), current, f); }
>
> This code writes a 10mbyte file to disk in about 2.2 seconds on a
> typical system. Can someone suggest an improvement please?
>
> Sincerely,
> Ondrej Zara
>
> >


--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to