calloc
A simple, dependency free wrapper for managing your C string allocations in Go.
Installation
go get -u github.com/leaanthony/calloc
Usage
- Create a new allocator:
c := calloc.New()
- Defer the free method:
defer c.Free()
- Start creating C strings:
myCString := c.String("I am a C string")
Why?
It's a common pattern when using CGO to allocate C strings, use them in
a CGO call then deallocate them once the call is complete. This tiny
module not only cleans up your code but ensures that all allocated memory
gets freed.
NOTE: The library isn't thread safe as it is not intended to be shared
between threads. It is better to create new allocators where needed.