Skip to content

Commit

Permalink
Updated README to 0.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
lh3 committed Mar 15, 2016
1 parent 8094ccb commit 6d8797c
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
FAQ
---

####1. What is K8?
#### 1. What is K8?

K8 is a Javascript shell based on Google's [V8 Javascript engine][1]. It adds
the support of flexible byte arrays and file I/O. K8 is implemented in one C++
source file. The only dependency is zlib in addition to V8.

####2. There are many Javascript shells with much richer features. What makes K8 special?
#### 2. There are many Javascript shells with much richer features. What makes K8 special?

To some extent, [Node.js][2], [Narwhal][3], [SilkJS][4], [TeaJS][5] and
[Sorrow.js][6] are all Javascript shells. They not only provide binary storage
Expand All @@ -25,9 +25,10 @@ we even do not have a JS shell matching the usability of C, let alone
high-level programming languages such as Perl and Python.

K8 aims to provide C-like file I/O APIs. It adds a `File` object for buffered
file reading and a `Bytes` object for flexible binary storage.
file reading, a `Bytes` object for flexible binary storage and a `Map` object
for a hash map without hitting the memory limit of V8.

####3. How to compile K8? Are there compiled binaries?
#### 3. How to compile K8? Are there compiled binaries?

You need to first compile V8 and then compile and link K8. Here is the full procedure:

Expand All @@ -42,7 +43,7 @@ maybe in a deeper directory, depending on the OS.
Alternatively, you may download the compiled binaries for Mac and Linux from
[SourceForge][11]. The source code is also included.

####4. An earlier version of K8 implemented a generic buffered stream. Why has it been removed?
#### 4. An earlier version of K8 implemented a generic buffered stream. Why has it been removed?

To implement a generic buffered stream, we need to call a Javascript `read`
function in C++ and transform between Javascript and C++ data representation.
Expand All @@ -58,7 +59,7 @@ All the following objects manage some memory outside the V8 garbage collector.
It is important to call the `close()` or the `destroy()` methods to deallocate
the memory to avoid memory leaks.

###Example
### Example

var x = new Bytes(), y = new Bytes();
x.set('foo'); x.set([0x20,0x20]); x.set('bar'); x.set('F', 0); x[3]=0x2c;
Expand All @@ -72,7 +73,7 @@ the memory to avoid memory leaks.
s.close(); x.destroy();
}

###The Bytes Object
### The Bytes Object

`Bytes` provides a byte array. It has the following methods:

Expand Down Expand Up @@ -117,7 +118,7 @@ the memory to avoid memory leaks.
// Convert the byte array to string
Bytes.prototype.toString()

###The File Object
### The File Object

`File` provides buffered file I/O. It has the following methods:

Expand Down Expand Up @@ -157,6 +158,29 @@ the memory to avoid memory leaks.
// Close the file
File.prototype.close()

### The Map Object

`Map` provides a hash map implementation without using memory managed by V8. This can be helpful
when we want to stage a huge hash table in memory. `Map` has the following methods:

// Initialize a hash map
new Map()

// Put a key-value string pair to a hash map
Map.prototype.put(key, value)

// Equivalent to 'Map.prototype.put(key, "")'
Map.prototype.put(key)

// Get a key. Return 'null' if 'key' is non-existing
string Map.prototype.get(key)

// Delete a key.
Map.prototype.del(key)

// Deallocate memory
Map.prototype.destroy()

[1]: http://code.google.com/p/v8/
[2]: http://nodejs.org/
[3]: https://github.com/tlrobinson/narwhal
Expand Down

0 comments on commit 6d8797c

Please sign in to comment.