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

Already on GitHub? Sign in to your account

x/mobile/bind: byte slice parameter support without copy #12113

Closed
hyangah opened this Issue Aug 11, 2015 · 4 comments

Comments

Projects
None yet
5 participants
Contributor

hyangah commented Aug 11, 2015

When a Go function or method taking a byte slice is called, the current implementation
creates a copy of the arguments and passes it to the Go function. The implementation
was based on the assumption that the Go function is free to keep the slice for later use.
This prevents implementation like io.Read([]byte) where the parameter's content
is modified during call. Moreover, it costs an extra copy & memory which can be significant
depending on the byte slice size.

Instead, I propose to pass a slice backed by the foreign language's byte array if possible.

Users who want to keep the slice for later use have to be aware of the limitation and somehow
create a copy for now.

More discussion on automation or tool support to detect such use cases
(another kind of escape analysis) is welcome.

@crawshaw

@hyangah hyangah self-assigned this Aug 11, 2015

@hyangah hyangah added a commit to golang/mobile that referenced this issue Aug 11, 2015

@hyangah @hyangah hyangah + hyangah bind: update doc to include objective-C interface type support.
Also mention the current limitation in byte slice binding.
golang/go#12113.

Change-Id: Ie75780c2d203431ca26a188dfdb8f000f6805c18
Reviewed-on: https://go-review.googlesource.com/13531
Reviewed-by: David Crawshaw <crawshaw@golang.org>
73792b1

@ianlancetaylor ianlancetaylor added this to the Unreleased milestone Aug 11, 2015

Contributor

hyangah commented Oct 21, 2015

I plan to work on this in Nov.

CL https://golang.org/cl/19821 mentions this issue.

Hello,
Please help me out.

I created a golang function with returntype array
it is not created function with array return type, with message
"skipped function with unsupported return type or parameter"
eg.

my golang function is
unc Sample() []string {

letters := []string{"a", "b", "c", "d"}
return letters

}

and after this i run the bind command it generate the framework and show header file with following result.
"skipped function Sample with unsupported parameter or return types"

Contributor

eliasnaur commented Apr 20, 2016

Gomobile does not (yet) support binding to function that takes or returns slices or arrays. If you need access to a Go slice or array from native code, use something like:

func LetterAt(i int) string {
    return letters[i]
}

Please use the golang-nuts discussion group for support questions in the future:

https://groups.google.com/d/forum/golang-nuts

@gopherbot gopherbot locked and limited conversation to collaborators Apr 20, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.