lua-users home
lua-l archive

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


That's interesting! Given that I'm more interested in speed than memory
tightness, I guess there would be mileage in running out and writing a
super simplistic free-list-allocator-thing of 32 byte blocks used for
any lua allocs between 20 and 32 bytes...
A

-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Luiz Henrique
de Figueiredo
Sent: 08 July 2005 11:26
To: Lua list
Subject: Re: Heap memory issues for Embedded Systems

> Has anyone instrumented Lua to see what block sizes are common? Or is
this
> likely to vary from project to project? I'm thinking that a
sub-allocator
> for the common cases (or at least a free list) could be a significant
win.

I think it's likely to depend on the application because string and
closure
structs are allocated with a varying tail. However, simple value structs
are
likely to be the most frequent.

Here is the result of "lua /dev/null" for Lua 5.1w6. The first column is
the
number of requests for a block of the size given in the second column.
The
alloc function (to replace the one in lauxlib.c) is given at the end.
Running "lua life.lua" shows a different pattern,  although the top 10
are
the same (in a slightly different order).

    169	20
     39	22
     38	21
     31	23
     27	32
     23	24
     16	28
     14	25
     12	56
     10	224
     10	112
      9	19
      7	27
      6	448
      4	26
      3	896
      2	31
      2	29
      2	16
      2	12
      1	91
      1	88
      1	76
      1	72
      1	540
      1	512
      1	348
      1	34
      1	256
      1	192
      1	18
      1	1792
      1	17
      1	128
      1	1024

static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
  static size_t total=0;
  static int time=0;
  void *optr=ptr;
  (void)ud;
  (void)osize;
  ++time;
  if (nsize == 0) {
    free(ptr);
    total-=osize;
    printf(">>> %p %p %8d - T=%d O=%d
N=%d\n",ptr,optr,time,total,osize,nsize);
    return NULL;
  }
  else {
    total+=nsize-osize;
    ptr=realloc(ptr, nsize);
    printf(">>> %p %p %8d %c T=%d O=%d
N=%d\n",ptr,optr,time,osize==0?'+':'=',total,osize,nsize);
    return ptr;
  }
}

--lhf