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

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

hyangah opened this issue Aug 11, 2015 · 4 comments

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

hyangah opened this issue Aug 11, 2015 · 4 comments


Copy link

@hyangah 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.


@hyangah hyangah self-assigned this Aug 11, 2015
hyangah added a commit to golang/mobile that referenced this issue Aug 11, 2015
Also mention the current limitation in byte slice binding.

Change-Id: Ie75780c2d203431ca26a188dfdb8f000f6805c18
Reviewed-by: David Crawshaw <>
@ianlancetaylor ianlancetaylor added this to the Unreleased milestone Aug 11, 2015
Copy link
Contributor Author

@hyangah hyangah commented Oct 21, 2015

I plan to work on this in Nov.

Copy link

@gopherbot gopherbot commented Feb 22, 2016

CL mentions this issue.

Copy link

@nishant-kumbhare nishant-kumbhare commented Apr 20, 2016

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"

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"

Copy link

@eliasnaur 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:

@golang golang 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.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.