lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Tore Lund wrote:
> 
> Then there is the data segment, which is also 64 KB.  I hope and pray
> that the space left after heap, stack, etc. have been allocated will
> suffice.  But I have my doubts when I see how much bytecode is produced
> by relatively small source files.

IMHO you won't be very satisfied with Lua with only 64KB data area.
You can make it run with such a small amount of memory but doing
anything useful may become really difficult.  I must admit that
I never tried to run Lua myself on this kind of system.  It's
just what I think about how it would be ;-)

- Lua handles "out of memory" very badly.  If an OOM happens, an
exception is throw.  The virtual machines stays alive and consistent
but the running Lua application may lose data.

- This is even worse because of the garbage collector.  It's normally
activated if twice the memory is allocated as was in use after the last
GC cycle; i.e. if the GC found out, that for example 10KB was in use,
the GC will be started next time when a total of more than 20KB is
malloced (incl the old 10KB).  So, to avoid OOM errors, you can't have
more than 32KB of "live" data.  If you subtract the C stack and memory
used by the C library it gets even less.

- Lua's objects have some overhead that is no longer negligible when
having only 32KB usable malloc area.  I.e. each element in a table
takes 14 bytes with 16bit ints/pointers and 32bit longs/numbers.
Each string would take 12bytes + its length (not counting malloc
overhead).  And then some data structures are allocated in powers
of two.  As an example: standard Lua has already malloced 22.7KB
on my system after initializing.  You wont get many objects in
this 32KB.  And then there's heap fragmentation...

IMHO Lua's not really good for this kind of environment.  It's
not that it _wastes_ memory, but it was not designed for these
memory constraints (low overhead, compact data, fragmentation
avoidance, ...).  I.e. Forth is a masterpiece in this area.
[please not another "other language" thread :-)]

I would say with same work in the malloc area [1] 128KB heap
size is a reasonable low limit for Lua.

Ciao, ET.

[1] i.e. limiting the GCthreshold with early (synchronous) OOM
warnings.  May even be a useful feature for standard Lua...