unsafe

package
v0.0.1-really Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2019 License: Apache-2.0 Imports: 2 Imported by: 6 modules, 22 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToString

func BytesToString(src []byte) (d string)

BytesToString casts src to a string without extra memory allocation. The string returned by this function shares memory with "src".

Example
package main

import (
	"fmt"

	"github.com/grailbio/base/unsafe"
)

func main() {
	fmt.Println(unsafe.BytesToString([]byte{'A', 'b', 'C'}))
}
Output:
AbC

func ExtendBytes

func ExtendBytes(dptr *[]byte, newLen int)

ExtendBytes extends the given byte slice, without zero-initializing the new storage space. The caller must guarantee that cap(d) >= newLen (using e.g. a Grow() call on the parent buffer).

Example
package main

import (
	"fmt"

	"github.com/grailbio/base/unsafe"
)

func main() {
	d := []byte{'A', 'b', 'C'}
	d = d[:1]
	unsafe.ExtendBytes(&d, 2)
	fmt.Println(d)
}
Output:
[65 98]

func StringToBytes

func StringToBytes(src string) (d []byte)

StringToBytes casts src to []byte without extra memory allocation. The data returned by this function shares memory with "src".

Example
package main

import (
	"fmt"

	"github.com/grailbio/base/unsafe"
)

func main() {
	fmt.Println(unsafe.StringToBytes("AbC"))
}
Output:
[65 98 67]

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL