Код: Выделить всё
std::vector genVector() {
return std::vector(12, 0);
}
EMSCRIPTEN_BINDINGS(some_module) {
emscripten::register_vector("Uint8Array");
function("genVector", &genVector);
}
< /code>
Чтение Elcist#Advanced Class-Concepts и встроенные конверсии типа (Emscripten Emplece), кажется, что, поскольку он возвращается по значению, мне не пришлось бы вызовать Delete на стороне JS. Похоже, они также не звонят в свои примеры. Я также попытался указать return_value_policy :: take_ownership Я пытался register_vector ("vector ") , но это привело к ошибке TSC компиляции в сгенерированной из-за EMCC , сгенерированной некоторой_модуле.
Код: Выделить всё
function printWasmHeapInfo(Module, description = "I forgot to supply an arg") {
const LABEL_WIDTH = 18;
const VALUE_WIDTH = 15;
let total = 0;
let used = undefined;
let free = undefined;
let heapBase = undefined;
let heapEnd = undefined;
let note = undefined;
console.log(description);
if (Module.HEAP8 && Module.HEAP8.buffer) {
total = Module.HEAP8.buffer.byteLength;
} else if (Module.wasmMemory && Module.wasmMemory.buffer) {
total = Module.wasmMemory.buffer.byteLength;
} else {
console.error("Cannot find WASM heap or memory buffer on Module");
return;
}
try {
if (
Module.asm &&
Module.asm.__heap_base &&
typeof Module.asm.__heap_base.value === "number"
) {
heapBase = Module.asm.__heap_base.value;
}
} catch (e) {
console.error("an error occured A");
}
try {
if (typeof Module._sbrk === "function") {
heapEnd = Module._sbrk(0);
}
} catch (e) {
console.error("an error occured B");
}
if (heapBase !== undefined && heapEnd !== undefined) {
used = heapEnd - heapBase;
free = total - heapEnd;
} else if (heapEnd !== undefined) {
used = heapEnd;
free = total - heapEnd;
} else {
note = "Used/free heap size not available (Module._sbrk not exported)";
}
// Helper for right-justified values
function formatRow(label, value) {
let valStr = value !== undefined ? value.toString() : "?";
return label.padEnd(LABEL_WIDTH) + valStr.padStart(VALUE_WIDTH);
}
console.log(formatRow("Total heap size:", total));
console.log(formatRow("Used heap size:", used));
console.log(formatRow("Free heap size:", free));
if (heapBase !== undefined) console.log(formatRow("Heap base:", heapBase));
if (heapEnd !== undefined) console.log(formatRow("Heap end:", heapEnd));
if (note) console.log(note);
console.log("");
}
Чего мне не хватает? Помогите, пожалуйста,
Изменить: добавлена ссылка на встроенные конверсии
Подробнее здесь: https://stackoverflow.com/questions/796 ... r-by-value
Мобильная версия