Coder Social home page Coder Social logo

Can I use malloc? about nottinygc HOT 4 CLOSED

tillknuesting avatar tillknuesting commented on June 4, 2024
Can I use malloc?

from nottinygc.

Comments (4)

anuraaga avatar anuraaga commented on June 4, 2024 1

Hi @tillknuesting - at the time, the plan was for TinyGo to stop exporting those in 0.28.0 so did not export them here either. But it looks like that didn't happen yet, let me confirm if this is a long-term decision to keep the exports, and if so we'll add them.

tinygo-org/tinygo#3142 (comment)

In the meantime, you can define your own functions if needed

import "C"

//export allocate
func allocate(size uint32) unsafe.Pointer {
  // IIRC, the type actually is unsigned long in wasi-libc source for some reason, or otherwise whatever C. cast works :)
  return C.malloc(C.ulong(size))
}

//export deallocate
func deallocate(ptr unsafe.Pointer) {
  C.free(ptr)
}

from nottinygc.

anuraaga avatar anuraaga commented on June 4, 2024 1

@tillknuesting Thanks for bringing this up, I have made the change to export malloc/free by default. Will try to cut a release soon after debugging #13 further

from nottinygc.

tillknuesting avatar tillknuesting commented on June 4, 2024

Can we export this

func alloc(size uintptr, layout unsafe.Pointer) unsafe.Pointer {
?

TinyGo does https://github.com/tinygo-org/tinygo/blob/d01d85930d19a73010853b7ba8648d8811891bee/src/runtime/arch_tinygowasm_malloc.go#L13

from nottinygc.

anuraaga avatar anuraaga commented on June 4, 2024

Oh, I found this even simpler workaround

tetratelabs/wazero#1429 (comment)

I think we'll probably end up exporting by default here to match 0.28 but let me hear a bit on what the plan on TinyGo is first.

from nottinygc.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.