Skip to content

Commit 6d8797c

Browse files
committed
Updated README to 0.2.2
1 parent 8094ccb commit 6d8797c

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

README.md

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
FAQ
22
---
33

4-
####1. What is K8?
4+
#### 1. What is K8?
55

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

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

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

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

30-
####3. How to compile K8? Are there compiled binaries?
31+
#### 3. How to compile K8? Are there compiled binaries?
3132

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

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

45-
####4. An earlier version of K8 implemented a generic buffered stream. Why has it been removed?
46+
#### 4. An earlier version of K8 implemented a generic buffered stream. Why has it been removed?
4647

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

61-
###Example
62+
### Example
6263

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

75-
###The Bytes Object
76+
### The Bytes Object
7677

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

@@ -117,7 +118,7 @@ the memory to avoid memory leaks.
117118
// Convert the byte array to string
118119
Bytes.prototype.toString()
119120

120-
###The File Object
121+
### The File Object
121122

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

@@ -157,6 +158,29 @@ the memory to avoid memory leaks.
157158
// Close the file
158159
File.prototype.close()
159160

161+
### The Map Object
162+
163+
`Map` provides a hash map implementation without using memory managed by V8. This can be helpful
164+
when we want to stage a huge hash table in memory. `Map` has the following methods:
165+
166+
// Initialize a hash map
167+
new Map()
168+
169+
// Put a key-value string pair to a hash map
170+
Map.prototype.put(key, value)
171+
172+
// Equivalent to 'Map.prototype.put(key, "")'
173+
Map.prototype.put(key)
174+
175+
// Get a key. Return 'null' if 'key' is non-existing
176+
string Map.prototype.get(key)
177+
178+
// Delete a key.
179+
Map.prototype.del(key)
180+
181+
// Deallocate memory
182+
Map.prototype.destroy()
183+
160184
[1]: http://code.google.com/p/v8/
161185
[2]: http://nodejs.org/
162186
[3]: https://github.com/tlrobinson/narwhal

0 commit comments

Comments
 (0)