Rockbox Technical Forums

Rockbox Development => Starting Development and Compiling => Topic started by: myrockboxacct on February 22, 2012, 07:17:52 AM

Title: "out of memory" when making a program with lots of drawpixel() calls
Post by: myrockboxacct on February 22, 2012, 07:17:52 AM
I am trying to make a short "video" for my sansa clip v2.
I have a .c file with tons of rb->lcd_drawpixel() calls. (about 128*64 pixels * hundreds of frames)
The .c file itself is 2 megabytes.

When I type "make" from the build folder, it says "out of memory allocating 547340640 bytes after a total of 496640000 bytes".  Please tell me how to fix this.

Someone told me I should use a data file and that I couldn't have so much stuff in a .c or .h file.
Is he right?
How do I make a data file?  Can I google that question or is there some special rockbox format for that?
How do I read the data?
Do I have to use this?:
int read(int fildes, void *buf, size_t nbyte);
The read() function attempts to read nbyte bytes from the file associated
with the open file descriptor, fildes, into the buffer pointed to by buf.
I'm a C and Linux beginner.  How do I learn these things? Google? I don't understand the function parameters.

Code: [Select]
rb->lcd_clear_display();rb->lcd_drawpixel(104,22);rb->lcd_drawpixel(104,23);rb->lcd_drawpixel(104,24);rb->lcd_drawpixel(104,25);
rb->lcd_drawpixel(104,58);rb->lcd_drawpixel(104,59);rb->lcd_drawpixel(104,60);rb->lcd_update();rb->sleep(sleeptime);
/* Then theres a million more of the above*/
Thanks for helping.
Title: Re: "out of memory" when making a program with lots of drawpixel() calls
Post by: Llorean on February 22, 2012, 07:54:30 AM
You should really, really take a step back and find a good C tutorial. Learning the language, how programs work, and what a compiler's doing will benefit you a lot in being able to figure things out. While trying to get started by diving in head first is commendable, background material will save you a lot of time and frustration in the long term.
Title: Re: "out of memory" when making a program with lots of drawpixel() calls
Post by: myrockboxacct on February 22, 2012, 08:43:49 AM
How do I make a data file?  Can I google that question or is there some special rockbox way to do that?
How do I read the data?  Can I google that question or is there some special rockbox way to do that?
Title: Re: "out of memory" when making a program with lots of drawpixel() calls
Post by: Llorean on February 22, 2012, 08:59:48 AM
See, that's the thing. It doesn't even look like you're asking the right questions. It looks, based on the code sample, that you'd probably be better off drawing things with a few basic algorithms rather than stating each individual drawpixel. Which would affect how you create the data file (since you'd need to decide the format of the data). How you read said file can mostly be worked out by looking at other programs that load files, of which there are many.

Trying to solve this by asking one question at a time is just going to result in people writing half your program for you, and you not really understanding well what you're doing. If you take the time to stop and learn C, you'll have a skill that's more reusable, and when you do stop by to ask questions they'll much more often be useful ones, and much less often be ones where someone says "I think you're going about this all wrong." Which, I suspect you are, again, based on the code snippet.
Title: Re: "out of memory" when making a program with lots of drawpixel() calls
Post by: nls on February 22, 2012, 02:01:59 PM
How to deal with files in rockbox is just like standard posix c, you'll find lots of info about it on the net. The format of your data file(s) is up to you. As you probably have figured out, doing what you're doing isn't the right way, drawing graphics isn't what the lcd_drwapixel function is intended for. Take some time looking at the plugin api and you'll see we have other drawing functions that can for example draw bitmaps. These rockbox specific functions you will probably not find much about by googling, the best docs there are is the source code for the functions themselves and other plugins using them.
Title: Re: "out of memory" when making a program with lots of drawpixel() calls
Post by: myrockboxacct on February 22, 2012, 09:09:03 PM
Lorean not really. Looks more like you're giving useless answers compared with nls's.  Thanks nls.
Title: Re: "out of memory" when making a program with lots of drawpixel() calls
Post by: Llorean on February 22, 2012, 10:47:04 PM
Bitmap drawing functions are an algorithmic drawing function, which work great if you're using bitmap data. Which is a type of data. Which is *exactly* what my response was leading to.

Believe it or not, I'm not giving a useless answer. You really should learn C first. It's like trying to build a house without learning about basic architecture. You can probably do it, but it's not going to be as sturdy without the proper education first.
Title: Re: "out of memory" when making a program with lots of drawpixel() calls
Post by: saratoga on February 23, 2012, 07:00:25 PM
3 deleted posts in a row.  I think myrockboxacct has gotten about as much help as he wants.