-
Notifications
You must be signed in to change notification settings - Fork 82
/
env.go
29 lines (25 loc) · 784 Bytes
/
env.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package levigo
// #cgo LDFLAGS: -lleveldb
// #include "leveldb/c.h"
import "C"
// Env is a system call environment used by a database.
//
// Typically, NewDefaultEnv is all you need. Advanced users may create their
// own Env with a *C.leveldb_env_t of their own creation.
//
// To prevent memory leaks, an Env must have Close called on it when it is
// no longer needed by the program.
type Env struct {
Env *C.leveldb_env_t
}
// NewDefaultEnv creates a default environment for use in an Options.
//
// To prevent memory leaks, the Env returned should be deallocated with
// Close.
func NewDefaultEnv() *Env {
return &Env{C.leveldb_create_default_env()}
}
// Close deallocates the Env, freeing the underlying struct.
func (env *Env) Close() {
C.leveldb_env_destroy(env.Env)
}