Skip to content

Commit

Permalink
memfs: allow owning non-HEAP buffers with ALLOW_MEMORY_GROWTH
Browse files Browse the repository at this point in the history
Memory growth may obsolete HEAP references, hence memfs disables 'canOwn' and forces copying.
memfs tests for this situation and suggests using --no-heap-copy.

However, the test is too strict: the same warning also appears with --no-heap-copy.

The test needs only prevent copying from HEAP, and accept other sources (e.g. xhr.response).
  • Loading branch information
Beuc committed Oct 28, 2019
1 parent fe35baf commit 26cc238
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/library_memfs.js
Expand Up @@ -273,19 +273,22 @@ mergeInto(LibraryManager.library, {
// of bytes anymore since their contents now represent file data inside the filesystem.
write: function(stream, buffer, offset, length, position, canOwn) {
#if ALLOW_MEMORY_GROWTH
// If memory can grow, we don't want to hold on to references of
// the memory Buffer, as they may get invalidated. That means
// we need to do a copy here.
// If the buffer is located in main memory (HEAP), and if
// memory can grow, we can't hold on to references of the
// memory buffer, as they may get invalidated. That means we
// need to do copy its contents.
if (buffer === HEAP8.buffer || buffer.buffer === HEAP8.buffer) {
#if ASSERTIONS
// FIXME: this is inefficient as the file packager may have
// copied the data into memory already - we may want to
// integrate more there and let the file packager loading
// code be able to query if memory growth is on or off.
if (canOwn) {
warnOnce('file packager has copied file data into memory, but in memory growth we are forced to copy it again (see --no-heap-copy)');
}
// FIXME: this is inefficient as the file packager may have
// copied the data into memory already - we may want to
// integrate more there and let the file packager loading
// code be able to query if memory growth is on or off.
if (canOwn) {
warnOnce('file packager has copied file data into memory, but in memory growth we are forced to copy it again (see --no-heap-copy)');
}
#endif // ASSERTIONS
canOwn = false;
canOwn = false;
}
#endif // ALLOW_MEMORY_GROWTH

if (!length) return 0;
Expand Down

0 comments on commit 26cc238

Please sign in to comment.