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