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

Why PlatON wasm vm supports memory malloc functions #56

Closed
MaggieNgWu opened this issue May 13, 2019 · 6 comments
Closed

Why PlatON wasm vm supports memory malloc functions #56

MaggieNgWu opened this issue May 13, 2019 · 6 comments

Comments

@MaggieNgWu
Copy link

MaggieNgWu commented May 13, 2019

Hi, guys

I was wondering why PlotON VM supply functions of "malloc" and "free" memory.

"malloc":  &exec.FunctionImport{Execute: envMalloc, GasCost: envMallocGasCost},
"free":    &exec.FunctionImport{Execute: envFree, GasCost: envFreeGasCost},
"calloc":  &exec.FunctionImport{Execute: envCalloc, GasCost: envCallocGasCost},
"realloc": &exec.FunctionImport{Execute: envRealloc, GasCost: envReallocGasCost},

This struct seems like defined by PlatON. As I have known, memory in WAVM is a byte array, used by program to store string and other values. The memory can be managed by WAVM. So, why PlatON would like to define this Memory structure and supply "malloc" function for smart contracts?

type Memory struct {
	Memory []byte
	Start  int //start position for malloc
	Size   int //memory size for malloc
	tree   []int
}
@woda0109
Copy link

Efficient use of memory, reusing destructed memory.

@MaggieNgWu
Copy link
Author

What is the mechanism of the memory use?/ How PlatON manage wavm memory?
(We can use Chinese if you like)

@jiangshangqifeng
Copy link
Contributor

The question you mentioned is more detailed and may not be clearly described in a few words. Do you have any problems during the specific application development process? You can send a look at the specific problems you have encountered. thx @MaggieNgWu

@MaggieNgWu
Copy link
Author

Let's make it simple. In which case, a smart contract wasm code would call "malloc" function?

@jiangshangqifeng
Copy link
Contributor

you can use ‘malloc' as you need
I suggest you debug the code and see the details :)

@MaggieNgWu
Copy link
Author

Would you please make an example?

benbaley pushed a commit that referenced this issue Aug 14, 2019
benbaley pushed a commit that referenced this issue Sep 7, 2019
@benbaley benbaley closed this as completed Jan 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants