From da16be98e013873d02350a3bb1da781f10405e39 Mon Sep 17 00:00:00 2001 From: fumiama Date: Sun, 8 Aug 2021 11:19:04 +0800 Subject: [PATCH] add free --- README.md | 2 +- conv.go | 2 ++ mem.go | 10 ++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 mem.go diff --git a/README.md b/README.md index edf6800..3ba3094 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Turn the result to its original coding form to decode. # Usage ## As package -Just include it in your project. +Just import it in your project. ## As lib Copy this repo to `$GOPATH/src`, then execute ```bash diff --git a/conv.go b/conv.go index 1cc32f9..f91099b 100644 --- a/conv.go +++ b/conv.go @@ -6,10 +6,12 @@ import ( var format = unicode.UTF16(unicode.BigEndian, unicode.IgnoreBOM) +// UTF16be2utf8 to display the result as string func UTF16be2utf8(b []byte) ([]byte, error) { return format.NewDecoder().Bytes(b) } +// UTF82utf16be to decode from string func UTF82utf16be(b []byte) ([]byte, error) { return format.NewEncoder().Bytes(b) } diff --git a/mem.go b/mem.go new file mode 100644 index 0000000..896add9 --- /dev/null +++ b/mem.go @@ -0,0 +1,10 @@ +package base14 + +// #include +import "C" +import "unsafe" + +// Free memory allocated by encode / decode +func Free(b []byte) { + C.free(unsafe.Pointer(&b[0])) +}