aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-08-27 14:17:38 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-08-27 14:17:38 -0700
commit3b2b7341aad1fb098b4a90a88ee8ee271b61e39a (patch)
tree77aa96f974c4bedd16d163fc8c9a96ae7ae43bfb
parent8c249ab4d5c786395ab6e7043e95a0a2387d4461 (diff)
copy the entire datafile in one chunk into the heap, avoiding one malloc per file, but at the cost of not being able to free them
-rw-r--r--src/library_memfs.js6
-rw-r--r--tools/file_packager.py16
2 files changed, 8 insertions, 14 deletions
diff --git a/src/library_memfs.js b/src/library_memfs.js
index 63326c42..354f5e95 100644
--- a/src/library_memfs.js
+++ b/src/library_memfs.js
@@ -2,17 +2,13 @@ mergeInto(LibraryManager.library, {
$MEMFS__deps: ['$FS'],
$MEMFS: {
// content modes
- CONTENT_OWNING: 1, // contains a subarray into the heap, and we own it - need to free() when no longer needed
+ CONTENT_OWNING: 1, // contains a subarray into the heap, and we own it, without copying (note: someone else needs to free() it, if that is necessary)
CONTENT_FLEXIBLE: 2, // has been modified or never set to anything, and is a flexible js array that can grow/shrink
CONTENT_FIXED: 3, // contains some fixed-size content written into it, in a typed array
ensureFlexible: function(node) {
if (node.contentMode !== MEMFS.CONTENT_FLEXIBLE) {
var contents = node.contents;
node.contents = Array.prototype.slice.call(contents);
- if (node.contentMode === MEMFS.CONTENT_OWNING) {
- assert(contents.byteOffset);
- Module['_free'](contents.byteOffset);
- }
node.contentMode = MEMFS.CONTENT_FLEXIBLE;
}
},
diff --git a/tools/file_packager.py b/tools/file_packager.py
index 2871f1ed..8a1f1ba5 100644
--- a/tools/file_packager.py
+++ b/tools/file_packager.py
@@ -344,14 +344,7 @@ if has_preloaded:
},
send: function() {},
onload: function() {
- var data = this.byteArray.subarray(this.start, this.end);
- var size = this.end - this.start;
- var ptr = Module['_malloc'](size); // XXX leaked if a preload plugin replaces with new data
- Module['HEAPU8'].set(data, ptr);
- var arrayBuffer = Module['HEAPU8'].subarray(ptr, ptr + size);
- assert(arrayBuffer, 'Loading file ' + name + ' failed');
- var byteArray = !arrayBuffer.subarray ? new Uint8Array(arrayBuffer) : arrayBuffer;
-
+ var byteArray = this.byteArray.subarray(this.start, this.end);
if (this.crunched) {
var ddsHeader = byteArray.subarray(0, 128);
var that = this;
@@ -419,7 +412,12 @@ for file_ in data_files:
if has_preloaded:
# Get the big archive and split it up
- use_data = ' DataRequest.prototype.byteArray = byteArray;\n'
+ use_data = '''
+ // copy the entire loaded file into a spot in the heap. Files will refer to slices in that. They cannot be freed though.
+ var ptr = Module['_malloc'](byteArray.length);
+ Module['HEAPU8'].set(byteArray, ptr);
+ DataRequest.prototype.byteArray = Module['HEAPU8'].subarray(ptr, ptr+byteArray.length);
+'''
for file_ in data_files:
if file_['mode'] == 'preload':
use_data += ' DataRequest.prototype.requests["%s"].onload();\n' % (file_['dstpath'])