github.com/secoba/wails/v2@v2.6.4/internal/frontend/desktop/darwin/calloc.go (about) 1 //go:build darwin 2 3 package darwin 4 5 /* 6 #include <stdlib.h> 7 */ 8 import "C" 9 import "unsafe" 10 11 // Calloc handles alloc/dealloc of C data 12 type Calloc struct { 13 pool []unsafe.Pointer 14 } 15 16 // NewCalloc creates a new allocator 17 func NewCalloc() Calloc { 18 return Calloc{} 19 } 20 21 // String creates a new C string and retains a reference to it 22 func (c Calloc) String(in string) *C.char { 23 result := C.CString(in) 24 c.pool = append(c.pool, unsafe.Pointer(result)) 25 return result 26 } 27 28 // Free frees all allocated C memory 29 func (c Calloc) Free() { 30 for _, str := range c.pool { 31 C.free(str) 32 } 33 c.pool = []unsafe.Pointer{} 34 }