Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

112
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!