Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HEAPU8 and _malloc #7437

Closed
yjjnls opened this issue Nov 2, 2018 · 2 comments
Closed

HEAPU8 and _malloc #7437

yjjnls opened this issue Nov 2, 2018 · 2 comments
Labels

Comments

@yjjnls
Copy link

yjjnls commented Nov 2, 2018

According to some examples, I found that Module._malloc() return the address of the alloced memory, something like the pointer.

But in the example below:

let data = new Uint8Array([0, 0, 0, 255, 0, 1, 2, 3]);
let dataPtr = cv._malloc(8);
let dataHeap = new Uint8Array(cv.HEAPU8.buffer, dataPtr, 8);

new Uint8Array(buffer [, byteOffset [, length]]);

byteOffset should be the offset in the buffer, but here dataPtr is passed in.

I don't know why?

According to the doc, byteOffset is the offset (in bytes) of the Uint8Array from the start of its ArrayBuffer. But what cv._malloc(8) returned is an address. The former is a relative address, the latter is an absolute address. I think they're different.

The example is from opencv.js, and it run correctly.

@kripken
Copy link
Member

kripken commented Nov 2, 2018

This stuff can be confusing, yeah. But HEAPU8.buffer is all of memory, so an offset on it is the same as an absolute offset.

@stale
Copy link

stale bot commented Nov 2, 2019

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant.

@stale stale bot added the wontfix label Nov 2, 2019
@stale stale bot closed this as completed Nov 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants