Giter Club home page Giter Club logo

leveldb-sharp's Introduction

leveldb-sharp is a portable C# binding for the C API of the LevelDB library.

To support the most reach leveldb-sharp is available under the 3-clause BSD license, which is the same license LevelDB uses.

leveldb-sharp uses the C API instead of the C++ API for portability. Using C++/CLI would have been the direct route but it is currently not portable outside of Windows. As I use the binding for Smuxi which targets Linux, Windows and OS X, the C API was the better pick.

Features

leveldb-sharp offers:

  • low-level function calls to LevelDB
  • high-level object oriented API with .NET enrichments (IEnumerable, IDisposable)
    • DB API
    • ReadOptions/WriteOptions/Options API
    • Write batch API
    • Iterator API
    • Cache API
    • Snapshot API
    • Compact range API
  • Allows combined use of low-level and high-level APIs
  • NUnit test-case coverage

Limitations

Currently leveldb-sharp lacks:

  • comparator API (unsafe code? no thanks...)

Download

Projects using leveldb-sharp

leveldb-sharp's People

Contributors

carlosmn avatar meebey avatar raymens avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

leveldb-sharp's Issues

Enhance memory management (Zero-Copy API)

leveldb-sharp currently copies the values returned from LevelDB using Marshal.PtrToStringAnsi() as the memory was allocated by LevelDB. The issue is that the CLR can not use memory owned / allocated by someone else it can't know when it needs to be released or if it was already released. The simple but not effective solution is to copy the memory to have it CLR owned. To make the situation even worse, the C binding of LevelDB also copies the values returned by LevelDB, see: http://codeofrob.com/entries/the-price-of-abstraction---using-leveldb-in-ravendb.html

After looking into this issue I came up these possible solutions how passing values can work:

  • copy unmanaged memory and make the copy managed: Marshal.PtrToStringAnsi()
    • Pros: safe, easy to implement, easy to use
    • Cons: copy overhead
  • return the pointer everywhere, as in IntPtr instead of a string or byte[] and let the user access that doing unsafe code blocks
    • Pros: most efficient
    • Cons: unsafe and ugly to use
  • implement a Slice type that operates on IntPtr and do unsafe code access on it and release the memory when needed (GCed). This would be basically a safe proxy around the unsafe memory.
    • Pros: safe, easy to use, most efficient

Quoting from Rob's blog:

MemoryStream stream = db.Get(string key)

"Where that stream reads from the start of an unmanaged array to the end of that unmanaged array and then disposes it."

This wouldn't work for us, as LevelDB reads the whole value into memory and returns that, instead of a stream...

Character conversion issues

I have found a problem when attempting to store data which contains non-ascii characters. "Décor" for example with the accented é.

The issue seems to be rooted in a mis-step with calculating the string length for passing from the managed c# to the un-managed leveldb.

The call to get the expected length uses the UTF8 encoding but then the actual marshaled call passes as the current ANSI code page. In the ANSI page (for a US system) the special é takes only a single byte but in UTF8 is takes 2 bytes.

The end result is that the record is saved with an extra character of garbage, specifically one extra garbage character for each special character in the input.

How did you compile leveldb on Windows?

Thanks for saving me tons of work here. These bindings look great and exactly what I am looking for. I was wondering however how you compiled leveldb on Windows. Some searching revealed few ports but I figured I could ask you since you have probably already experimented with some of them.

Thanks in advance!

license question

I just forked the project to add some features to use in one of my own personal projects.
Everything is fine and smooth until i decided to implement Slices.and I have no clue how my license should look like.I mean I'm not Google and not the original author either.
Could you help me in this?

Call to Marshal.FreeHGlobal fails

I am attempting to use your wrapper on a Windows machine (2008 R2) using the standard framework (i.e. not Mono).

When attempting to do a Get, the call to this method fails with the following error:

System.BadImageFormatException - Invalid access to memory location. (Exception from HRESULT: 0x800703E6)

Is this silently failing for you or is the pointer successfully deallocated?

DLL leveldb not found

´´´
Die DLL "leveldb": Das angegebene Modul wurde nicht gefunden. (Ausnahme von HRESULT: 0x8007007E) kann nicht geladen werden.

The DLL "leveldb": The selected Module could not be found, (Exception of HRESULT: 0x8007007E) could not be loaded.
´´´
I compiled the whole project over and over and it seems to have no fails in it.
Do I need to download a "leveldb.dll" from somewhere or how do I get that running?

Memory leaks

After some initial testing with 1.9.2 I found memory growth issues.
In Native.cs I changes all calls to the free method
From: leveldb_free(ptr);
To: leveldb_free(ref ptr);

And changed the associated import
[DllImport("libleveldb", CallingConvention = CallingConvention.Cdecl)]
public static extern void leveldb_free(ref IntPtr ptr);

All seems well after these changes. Though it does leave me a little uneasy that I'm not finding anyone else needing to make this change.

I'm using the kkowalczyk-leveldb-6f9f0bca2016 windows port of LevelDB itself.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.