Edit4: Last patch before I add this to SVN. Changed the free list logic to make alloc/free simpler. The getmeminfo values are mostly maintained dynamically instead of being calculated in each call to getmeminfo.
Thanks for doing this, and apologies for not being more involved, just now coming out of an RL crunch.
I ran the test msgtest test case on sx160 with patch 8, and it didn't crash. It does seem slower (~240 sec for 1k iterations), but I think this is expected because it's a pathological case.
I tried to do some general stress testing by allocating enough memory in lua to run through exmem, and got some odd results in get_meminfo
Test case in chdkptp is
=t={} i=1 repeat t[i]=string.rep(tostring(math.random(0xffff)),math.random(1,3)) i=i+1 until get_meminfo('exmem').free_block_max_size < 100 or i > 20000 return i,get_meminfo('exmem')
This generates a bunch of random strings until free_block_max_size gets below 100 (with a 20000 iteration limit just for sanity)
Doing this, it returns after a ~600 iterations with exmem meminfo like
allocated_size=150080,
free_size=236000,
free_block_count=6,
free_block_max_size=24,
Which doesn't make much sense to me, since ~230K in 6 free block should leave at least one bigger than 24.
sx160 has ARAM, exmem and a fair amount of Canon heap. In the normal CHDK code, the test should burn through ARAM and then exmem before putting much in the canon heap.
Changing the condition to free_size < 1000 runs longer, and appears to allocate more
con 33> =t={} i=1 repeat t[i]=string.rep(tostring(math.random(0xffff)),math.random(1,3)) i=i+1 until get_meminfo('exmem').free_size < 1000 or i > 20000 return i,get_meminfo('exmem')
34:return:4001
34:return:table:
...
free_size=924
allocated_size=357988,
free_block_count=44,
allocated_count=3485,
free_block_max_size=208
Doing a standalone get_meminfo('exmem') gives more expected results
free_size=270768
allocated_size=116360
free_block_count=1,
allocated_count=1,
free_block_max_size=270768,
total_size=387216
Incorrect free_block_max_size is potentially bad, because it's used as a proxy for free memory in some cases (core_get_free_memory)