avoid copying value twice during a get/1 (Howard Chu)
This commit is contained in:
parent
e52c879b18
commit
1a435eb761
2 changed files with 8 additions and 19 deletions
|
@ -70,7 +70,7 @@ $ ./start.sh
|
|||
|
||||
|
||||
####Note:
|
||||
The code below create a new database with **80GB** MapSize, **avoid fsync**
|
||||
The code below creates a new database with **80GB** MapSize, **avoid fsync**
|
||||
after each commit (for max speed) and use the experimental **MDB_FIXEDMAP**.
{ok, Handle} = emdb:open("/tmp/emdb2", 85899345920, ?MDB_NOSYNC bor ?MDB_FIXEDMAP).
|
||||
|
||||
Performance
-----------
For maximum speed, this library use only binaries for both keys and values.
|
||||
|
|
|
@ -65,7 +65,6 @@ static struct emdb_map_t * emdb_map = NULL;
|
|||
|
||||
/* emdb errors */
|
||||
#define EMDB_MALLOC_ERR "error_malloc"
|
||||
#define EMDB_MAKE_BINARY_ERR "error_make_binary"
|
||||
#define EMDB_CREATE_ERR "error_create"
|
||||
#define EMDB_MAPSIZE_ERR "error_mapsize"
|
||||
#define EMDB_OPEN_ERR "error_open"
|
||||
|
@ -237,8 +236,8 @@ static ERL_NIF_TERM emdb_get_nif (ErlNifEnv * env,
|
|||
int argc, const ERL_NIF_TERM argv[])
|
||||
{
|
||||
ErlNifBinary key;
|
||||
ErlNifBinary val;
|
||||
/* ERL_NIF_TERM term; */
|
||||
ErlNifBinary val = {0};
|
||||
ERL_NIF_TERM term;
|
||||
|
||||
MDB_val mkey;
|
||||
MDB_val mdata;
|
||||
|
@ -274,26 +273,16 @@ static ERL_NIF_TERM emdb_get_nif (ErlNifEnv * env,
|
|||
return atom_none;
|
||||
}
|
||||
|
||||
if (! enif_alloc_binary(mdata.mv_size, & val))
|
||||
FAIL_FAST(EMDB_MALLOC_ERR, err2);
|
||||
|
||||
memcpy(val.data, mdata.mv_data, mdata.mv_size);
|
||||
val.size = mdata.mv_size;
|
||||
val.data = mdata.mv_data;
|
||||
|
||||
term = enif_make_binary(env, &val);
|
||||
|
||||
mdb_txn_abort(txn);
|
||||
|
||||
return enif_make_tuple(env, 2,
|
||||
atom_ok,
|
||||
enif_make_binary(env, & val));
|
||||
|
||||
/* val.size = mdata.mv_size; */
|
||||
/* val.data = mdata.mv_data; */
|
||||
|
||||
/* mdb_txn_abort(txn); */
|
||||
|
||||
/* return enif_make_tuple(env, 2, */
|
||||
/* atom_ok, */
|
||||
/* term); */
|
||||
|
||||
term);
|
||||
|
||||
err2:
|
||||
mdb_txn_abort(txn);
|
||||
|
|
Loading…
Reference in a new issue