appcelerator/hyperloop-common — pull request #40 by infosia (2014-07-02 05:47:53+00:00)
Title: Add memory operations

Add support for direct memory access via JS. This treats memory as if it's JS array, which may be allocated by malloc/calloc etc and freed by free. Allocated memory has (void*) type, so it needs to cast to actual type (char* etc) when use with array. Unlike JS array, it doesn't have "length" field because allocated memory doesn't know its length.

```javascript
// allocate byte array (char *)
var pbyte = calloc(size_of_char,1024).cast('char *');

// get value from byte array
console.log(pbyte[123],'should be 0');

// set value to byte array
pbyte[123] = 45;

console.log(pbyte[123], 'should be 45');

// unlike JS array, "pbyte.length" does not work.
// this is because sizeof(void*) doesn't return allocated size.

free(pbyte);
```