android
  #21  
Old 01-18-2010, 06:41 PM
ThievingSix ThievingSix is offline
Member
 
Join Date: Aug 2008
Posts: 218
Default

Hmm, one of us doesn't understand tables(arrays) correctly. From my understanding:

Code:
for h=1,240 do
    BUFFER[h] = {};
      for l=1,400 do
       BUFFER[h][l] = 255;
       end;
end;
Doesn't just allocate what you ask. It uses an algorithm that will allocate further ahead of what you allocated to speed up assignment. Plus it's not just allocating room for the new number we are adding. Try outputting collectgarbage("count") to see how many kb's are actually being allocated.
Reply With Quote

Advertisement [Remove Advertisement]

  #22  
Old 01-18-2010, 06:57 PM
Jan_DK's Avatar
Jan_DK Jan_DK is offline
Junior Member
 
Join Date: Mar 2009
Location: Denmark
Posts: 88
Default

Looks like this works.

It load data from a Gif file 4 bytes at the time and transfer them to the buffer and
display the content in BUFFFER[1][1] = GIF8 0x47494638

Code:
color_black = color.new(0,0,0);
color_white = color.new(255,255,255);
text.color(color_white);
text.size(16);
screen.fillrect(0,0,400,240,color_black);
screen.update();

size = 4;
io.input("image.gif");

BUFFER = {} ;


for h=1,2 do
    BUFFER[h] = {};
      for l=1,20 do
         x = io.read(size);
         BUFFER[h][l] = x;
      end;
      screen.fillrect(0,0,400,240,color_black);
      text.draw(20,20,"BUFFER = "..h );
      screen.update();
end;

text.draw(20,50,"BUFFER[1][1] = "..BUFFER[1][1]);
text.draw(20,70,"BUFFER[1][2] = "..BUFFER[1][2]);
text.draw(20,90,"BUFFER[1][3] = "..BUFFER[1][3]);

screen.update();
os.sleep(1000);

Jan_DK
Reply With Quote

  #23  
Old 01-19-2010, 10:38 AM
Jan_DK's Avatar
Jan_DK Jan_DK is offline
Junior Member
 
Join Date: Mar 2009
Location: Denmark
Posts: 88
Default

Quote:
Originally Posted by ThievingSix View Post
Hmm, one of us doesn't understand tables(arrays) correctly.
That's properly me, I think I'm really not programming in Lua, but trying
to force my C programming knowledge about array's through in Lua.


Quote:
Code:
for h=1,240 do
    BUFFER[h] = {};
      for l=1,400 do
       BUFFER[h][l] = 255;
       end;
end;
Doesn't just allocate what you ask. It uses an algorithm that will allocate further ahead of what you allocated to speed up assignment. Plus it's not just allocating room for the new number we are adding. Try outputting collectgarbage("count") to see how many kb's are actually being allocated.
Reading this http://www.lua.org/pil/11.2.html
Matrices and Multi-Dimensional Arrays
.

I get the impression that Lua is even more effective and flexible than c when it
comes to arrays. I'm confused

Then how do we create a buffer the size of 400x240x3 bytes in Creative Lua ?

Jan_DK

Reply With Quote

  #24  
Old 01-19-2010, 01:04 PM
ThievingSix ThievingSix is offline
Member
 
Join Date: Aug 2008
Posts: 218
Default

This is where I get confused also: http://www.wowwiki.com/Lua_object_memory_sizes

"As indexes are added, the table will allocate space for new indexes at an exponential rate"

"If a table is indexed by sequential integers, each index will take 16 bytes (not including any memory allocated for the value)."

"A new, empty table will consume 40 bytes."

So with that information you get somethine like (32768 * (16 + 4)) + 40. Which is closer to the 800kb limit i notied here: http://www.anythingbutipod.com/forum...4&postcount=13
Reply With Quote

  #25  
Old 01-19-2010, 03:31 PM
Jan_DK's Avatar
Jan_DK Jan_DK is offline
Junior Member
 
Join Date: Mar 2009
Location: Denmark
Posts: 88
Default

Just tried this to be sure, it's not a indexing overflow problem but memory.

This is stopping at aprox. 16100 with an error.

Code:
for index=1,32000 do
    BUFFER[index] = 0xFF01FA02;
    BUFFER2[index] = 0xFA01FA22;
 end;
The question is, if we get 32768*4-128K usable bytes out of a
single dim array and 251K 157*400*4 out of a 2d, then what about adding more dimensions.

Jan_DK
Reply With Quote

  #26  
Old 01-19-2010, 07:38 PM
kushndonuts kushndonuts is offline
Junior Member
 
Join Date: Jan 2010
Location: Maryland
Posts: 29
Default

WOW i have no god damn clue what any of this means. But I think i get the gist of it. I just don't understand what you want in the long run of this.
Reply With Quote

  #27  
Old 01-21-2010, 12:21 PM
Jan_DK's Avatar
Jan_DK Jan_DK is offline
Junior Member
 
Join Date: Mar 2009
Location: Denmark
Posts: 88
Default

ThievingSix>>"So with that information you get somethine like (32768 * (16 + 4)) + 40. Which is closer to the 800kb limit i notied"

There is something very weird, that's for sure, adding one more dimension to the array, makes is possible to allocate more than 288.000 bytes as the screen require, but a 3 part loop and 4 bytes per read makes it unusable.


I've created a 400x240x3 288.000 bytes raw image data file, with the first bytes = ABCDEFG(so there is something to print) as a test file.
The loops allocates 290304 bytes, but what 288000 will be in BUFFER[?][?][?] i have no clue, for I would like to print the content of the last byte, like the first one. A 2 dimensional array the size of the screen make sense,
but this 3 loops stuff is to weird. :-)

Code:
color_black = color.new(0,0,0);
color_white = color.new(255,255,255);
text.color(color_white);
text.size(16);
screen.fillrect(0,0,400,240,color_black);
screen.update();

size = 4;
io.input("image_400x240x3.raw");
BUFFER = {} ;
for d=1,18 do
    BUFFER[d] = {};
    for h=1,63 do
        BUFFER[d][h] = {};
        for l=1,64 do
           if d*h*l*4 ~= 288000 then
           local x = io.read(size);
           BUFFER[d][h][l] = x;
           end;
        end;
    end;
    screen.fillrect(0,0,400,240,color_black);
    text.draw(20,20,"BUFFER = "..d*63*64*4 );
    screen.update();
end;
text.draw(20,50,"BUFFER[1][1][1] = "..BUFFER[1][1][1]);
screen.update();
os.sleep(500);
kushndonuts>> I just don't understand what you want in the long run of this.

In order to do anything beyond what the "SDK" provide eg. displaying
gif animation I think one needs to allocate some memory to work with.
And some of the threads above is an attempt to do just that, and then running into problems. :-)

Jan_DK

Last edited by Jan_DK; 01-22-2010 at 12:24 PM. Reason: changed: pixel to byte
Reply With Quote

  #28  
Old 01-21-2010, 01:48 PM
Jan_DK's Avatar
Jan_DK Jan_DK is offline
Junior Member
 
Join Date: Mar 2009
Location: Denmark
Posts: 88
Default

This code load the file into one string, and then extract the content and convert it to numbers for use in color function(r,g,b)
for drawing a pixel with the data from the file. What I don't know
is if the file is loaded into the 880kb memory or not.

Shit ! It' only works in the simulator, on the X-fi2 read("*all")
generate an error, so we can not load a 280kb file in lua.

Edit: changing the file size to 157kb and then it works on the X-Fi2.

Code:
color_black = color.new(0,0,0);
color_white = color.new(255,255,255);
text.color(color_white);
text.size(16);
screen.fillrect(0,0,400,240,color_black);
screen.update();

size = 4;
text.draw(10,10,"Loading File...");screen.update();
io.input("image_400x240x3.raw");
filedata = io.read("*all");
print(string.len(filedata));
text.draw(10,30,"File size = "..string.len(filedata).." Bytes");

byte_R_string = string.sub (filedata, 1,1 );
byte_G_string = string.sub (filedata, 2,2 );
byte_B_string = string.sub (filedata, 3,3 );

print(byte_R_string);
print(byte_G_string);
print(byte_B_string);

byte_R = string.byte(byte_R_string);
byte_G = string.byte(byte_G_string);
byte_B = string.byte(byte_B_string);

print(byte_R);
print(byte_G);
print(byte_B);

color_data = color.new(byte_R,byte_G,byte_B);
screen.drawpixel(200,120,color_data);

screen.update();
os.sleep(500);
Jan_DK

Last edited by Jan_DK; 01-21-2010 at 02:03 PM.
Reply With Quote

  #29  
Old 01-21-2010, 02:52 PM
ThievingSix ThievingSix is offline
Member
 
Join Date: Aug 2008
Posts: 218
Default

Can you output garbagecollect("count")? I'm curious to see if we get just about the size of the file or if it's much more. If it's the former I'd be pretty sad..
__________________
Only ONE more functions in the Wiki need addressing!
Zen X-Fi2 LUA Wiki
Want to protect your applications? Click Here!
Tower Defense Thread
Zen Lock - Protect Your Zen!
Reply With Quote

  #30  
Old 01-21-2010, 04:30 PM
Jan_DK's Avatar
Jan_DK Jan_DK is offline
Junior Member
 
Join Date: Mar 2009
Location: Denmark
Posts: 88
Default

Quote:
Originally Posted by ThievingSix View Post
Can you output garbagecollect("count")? I'm curious to see if we get just about the size of the file or if it's much more. If it's the former I'd be pretty sad..
I get error :attempt to call global 'garbagecollect' (a nil value)

garbagecollect("count");


Jan_DK
Reply With Quote

  #31  
Old 01-21-2010, 04:40 PM
ThievingSix ThievingSix is offline
Member
 
Join Date: Aug 2008
Posts: 218
Default

OIASJOIASHEQOIUIUQWH(*@!Y**LWK

sorry. collectgarbage("count")

<-- dyslectic.
__________________
Only ONE more functions in the Wiki need addressing!
Zen X-Fi2 LUA Wiki
Want to protect your applications? Click Here!
Tower Defense Thread
Zen Lock - Protect Your Zen!
Reply With Quote

  #32  
Old 01-22-2010, 12:17 PM
Jan_DK's Avatar
Jan_DK Jan_DK is offline
Junior Member
 
Join Date: Mar 2009
Location: Denmark
Posts: 88
Default

Quote:
Originally Posted by ThievingSix View Post
OIASJOIASHEQOIUIUQWH(*@!Y**LWK

sorry. collectgarbage("count")

<-- dyslectic.
That's more like it :-)
but what do the numbers tell us ?

In the sim and loading a 288.000 bytes file.
print(collectgarbage("count")); or
text.draw(10,50,"CollectGarbage = "..collectgarbage("count"));
output->
450.5361328125

In the sim and loading a 154.007 bytes file.
output->
254.3543xxx

On the X-Fi2 and loading a 154.007 bytes file.
text.draw(10,50,"CollectGarbageCount = "..collectgarbage("count"));
outputs->
251.5322265625

Jan_DK
Reply With Quote

  #33  
Old 01-22-2010, 12:44 PM
ThievingSix ThievingSix is offline
Member
 
Join Date: Aug 2008
Posts: 218
Default

It's the total amount of memory in use by lua in kilobytes.
__________________
Only ONE more functions in the Wiki need addressing!
Zen X-Fi2 LUA Wiki
Want to protect your applications? Click Here!
Tower Defense Thread
Zen Lock - Protect Your Zen!
Reply With Quote

  #34  
Old 01-22-2010, 02:29 PM
Jan_DK's Avatar
Jan_DK Jan_DK is offline
Junior Member
 
Join Date: Mar 2009
Location: Denmark
Posts: 88
Default

The maximum file size is somewhere between 203-237kb
203 work
237 don't work

I'm watching a doc called 'BBS the Documentary'
I could not help my self when i saw this Computer comparison table.

What about a 1565.00 dollar PC with 16kb RAM



I guess we should not complain about only having what we got

Jan_DK
Reply With Quote

  #35  
Old 01-22-2010, 04:01 PM
ThievingSix ThievingSix is offline
Member
 
Join Date: Aug 2008
Posts: 218
Default

Well if we were using 2 bit image files I wouldn't complain!
__________________
Only ONE more functions in the Wiki need addressing!
Zen X-Fi2 LUA Wiki
Want to protect your applications? Click Here!
Tower Defense Thread
Zen Lock - Protect Your Zen!
Reply With Quote

  #36  
Old 01-22-2010, 04:08 PM
Jan_DK's Avatar
Jan_DK Jan_DK is offline
Junior Member
 
Join Date: Mar 2009
Location: Denmark
Posts: 88
Default

You're right ! maybe we should check the X-Fi2's font for interesting chars
for making AscII art

But there is no problem loading a screen size image thru the image function
so it's not that bad.

Jan_DK
Reply With Quote

  #37  
Old 01-22-2010, 11:44 PM
badazzmofo badazzmofo is offline
Junior Member
 
Join Date: Dec 2009
Posts: 75
Default

that commie 64 actually has 64k upgradeable to 128k with the ram cartridge.
Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 03:25 AM.