Buffer type

41 views
Skip to first unread message

Tim Caswell

unread,
Apr 11, 2012, 1:05:38 PM4/11/12
to lu...@googlegroups.com
I've punted on adding a buffer type to luvit since the string type of lua is binary safe.  However we're finding more and more we need a mutable or at least appendable buffer type.

If lua had constrings (an implementation detail that makes string concat very fast) I would just say to build the string a byte or more at a time, but it doesn't and concatenating strings can be very expensive.

Some lua code gets around this by using arrays of strings (remember browsers used to have the same issue before V8 friends implemented constrings)

I don't want to depend on FFI like we currently do with the beta buffer type since that locks us into using luajit.  Yes luajit will stay the default engine (it's in the name after all).  But I want the flexibility to use vanilla lua if I want to.

What should our buffer type look like?

My two cases are building a binary string a piece at a time.  This means adding 4 bytes for a number, 8 for a larger number, n bytes for a string, etc..

The other case is actually changing values in place of a buffer.  I don't know as many use cases for this, but I'm sure they exists. (I used mutable buffers in node to implement an in-memory database that was GC friendly)

Ideas?

zx9597446

unread,
Apr 14, 2012, 8:56:47 AM4/14/12
to luvit
glad to hear this, the buffer type will be very useful for end users
who write application in real world, like me.
especially for fixed length protocol, which need to read n bytes to
buffer, if read length m < n, then continue
read into buffer start position m.

having slice also be very useful, someone can pass a slice to others
like codec.

another thing is endianess.

node's buffer class will be a good example I guess.
Reply all
Reply to author
Forward
0 new messages