GithubHelp home page GithubHelp logo

Invalid Access To Memory about leveldb HOT 4 CLOSED

ohenepee avatar ohenepee commented on June 28, 2024
Invalid Access To Memory

from leveldb.

Comments (4)

veelenga avatar veelenga commented on June 28, 2024

@ohenepee as far as i understand you need to move iterator to the next at the end of the loop. What's happening now:

x x x
^
iterator.valid? # => true
iterator.next   # => moves to the second value
iterator.key    # => second key

x x x
  ^
iterator.valid? # => true
iterator.next   # => moves to the third value
iterator.key    # => third key

x x x
    ^
iterator.valid? # => true
iterator.next   # => moves to the invalid pointer
iterator.key    # => Invalid memory access

from leveldb.

ohenepee avatar ohenepee commented on June 28, 2024

Yes! You're right, I just needed to move the iterator.next below the puts. Thanks also for your awesome elaboration on the subject.

while iterator.valid?
  puts "#{iterator.key} - #{iterator.value}"
  iterator.next
end

iterator.destroy

It works now without giving the INVALID ACCESS TO MEMORY error, however it still reads the whole database even though I explicitly asked the iterator to seek for a particular key prefix... unless perhaps I don't know how the iterator is supposed to work in this case, then I suppose its a bug.

In the example I gave in the first comment, if I ask the iterator ro seek for "messages", should it also print entries keyed with "locations" and "something" ?

from leveldb.

veelenga avatar veelenga commented on June 28, 2024

That's how leveldb works. Using a seek you find a start point for the iterator and it will iterate till the end (having the lexicographic order).

To filter only needed entries, you can stop when the first key with a wrong prefix occurs and break the loop:

iterator = LevelDB::Iterator.new(db)

iterator.seek("messages")
while iterator.valid?
  break unless iterator.key.starts_with?("messages")

  puts "#{iterator.key} - #{iterator.value}"
  iterator.next
end

iterator.seek("something")
...

iterator.destroy

Related reading: https://groups.google.com/forum/#!topic/leveldb/DRj0-t1hJ08

from leveldb.

ohenepee avatar ohenepee commented on June 28, 2024

You couldn't be more helpful... thanks a lot and stay blessed!

from leveldb.

Related Issues (3)

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.