Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow copying of lmdb::dbi instances #10

Open
snej opened this issue Mar 3, 2016 · 2 comments
Open

Allow copying of lmdb::dbi instances #10

snej opened this issue Mar 3, 2016 · 2 comments

Comments

@snej
Copy link

snej commented Mar 3, 2016

It makes sense that the env and txn classes are moveable but not copyable, since they represent resources that are closed on destruction. But dbi isn't like that — the destructor is a no-op. So I don't see a reason for not having a copy constructor and copying assignment.

Having these would make it cleaner to pass dbi instances as parameters, store them in member variables, etc.

@landtuna
Copy link

I think this issue makes the library hard to use in a multithreaded environment. The documentation for lmdb says of mdb_dbi_open, "After a successful commit the handle will reside in the shared environment, and may be used by other transactions." It also says, "This function must not be called from multiple concurrent transactions in the same process."

Together, I take it to mean that the main process should open a database once (inside a transaction) and then pass the dbi handle to each of the threads it spawns. Without being able to copy an lmdb::dbi, I think the only way to do this is to pass the underlying handle around.

@hoytech
Copy link

hoytech commented Oct 3, 2019

In my fork of this library (https://github.com/hoytech/lmdbxx) I have made lmdb::dbi instances copyable. I can't think of any situation where copying the dbi would cause a bug, and in many cases being able to copy dbis or pass them by value simplifies application code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants