Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

115
Visualizações
How pass array of array from javascript to assemblyscript

I have on javasctipt side an array of array structured as this:

const arrayOfArray = [ArrayBuffer, ArrayBuffer, ArrayBuffer, ...];
const dataLenght = 100; //lenght of arrays inside of array

I need to pass it to assembly script, below a sample code (javascript side):

const arrayOfPointers = new Uint32Array(arrayOfArray.lenght);
for (let arrayIndex = 0; arrayIndex < arrayOfArray.lenght; arrayIndex ++) {
    const myArray = new Uint8ClampedArray(arrayOfArray[arrayIndex]);
    for (let i = 0; i < dataLenght ; i++) { //I try to fill with sample values for test
        myArray [i] = arrayIndex * 7 + 7;
    }
    const myArrayPtr = __newArray(Int8Array_ID, myArray );
    arrayOfPointers [arrayIndex ] = myArrayPtr ;
}

const arrayOfPointersPtr = newArray(Int32Array_ID, arrayOfPointers);
const resultPtr = wasmModule.DoStuffs(arrayOfPointersPtr, dataLenght);
const mergedLayersBuffer = self.__getArray(resultPtr);

This instead is the code AssemblyScriptSide

export const Int8Array_ID = idof<Int8Array>();
export const Int32Array_ID = idof<Int32Array>();

export function mergeLayers(arrayOfArrayPointers: Array<usize>, dataLenght: i32): Uint8Array {
    const layer0Ptr : usize = arrayOfArrayPointers[0];
    const layer0Buffer: ArrayBuffer = changetype<ArrayBuffer>(layer0Ptr);
    const resultLayer: Uint8Array = Uint8Array.wrap(layer0Buffer);

    for (let i: i32 = 0; i < 10; i++) {
        const value: u8 = resultLayer[i];
        trace('Value', 1, value);
    }
    return resultLayer;
 }

I receive the pointers correctlu on assemblyscript side, but then I am unable to convert correctly the pointers back to Uint8ClampedArray and read values.

What Am I doing wrong, and how can I fix this code?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda