github.com/cellofellow/gopkg@v0.0.0-20140722061823-eec0544a62ad/database/leveldb/env.go (about) 1 // Copyright 2013 <chaishushan{AT}gmail.com>. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package leveldb 6 7 // #include <leveldb/c.h> 8 import "C" 9 10 // Env is a system call environment used by a database. 11 // 12 // Typically, NewDefaultEnv is all you need. Advanced users may create their 13 // own Env with a *C.leveldb_env_t of their own creation. 14 // 15 // To prevent memory leaks, an Env must have Close called on it when it is 16 // no longer needed by the program. 17 type Env struct { 18 env *C.leveldb_env_t 19 } 20 21 // NewDefaultEnv creates a default environment for use in an Options. 22 // 23 // To prevent memory leaks, the Env returned should be deallocated with 24 // Close. 25 func NewDefaultEnv() *Env { 26 return &Env{C.leveldb_create_default_env()} 27 } 28 29 // Close deallocates the Env, freeing the underlying struct. 30 func (env *Env) Close() { 31 C.leveldb_env_destroy(env.env) 32 }