Whats the memory for? - General Discussion and Assistance - CHDK Forum

Whats the memory for?

  • 9 Replies
  • 7592 Views
Whats the memory for?
« on: 29 / May / 2008, 12:20:02 »
Advertisements
Hi,

I've been thinking about all that memory (1Meg) on my A720IS.  I routinely take up 680K (the code in Diskboot.bin plus memory for two viewport buffers) without any obvious problems.  On the other hand I find it hard to believe that Canon just throws in 1 Meg of memory that it never uses.  Where does the memory get used?

Jon

*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: Whats the memory for?
« Reply #1 on: 29 / May / 2008, 12:39:03 »
Compared to the RAM a single RAW image requires, 1M is not that much at all, is it? Also, Digic III is still pretty new and they are probably planning to use it for a couple of years more so it's good to have some room for expansion without hardware modifications.

*

Offline DataGhost

  • ****
  • 314
  • EOS 40D, S5IS
    • DataGhost.com
Re: Whats the memory for?
« Reply #2 on: 29 / May / 2008, 12:43:56 »
Headroom, undoubtedly. There are a lot of calls to malloc, they don't always need all the memory. Also, the cameras have 32 or 64MB RAM, the 1MB set aside for malloc is just a small part of that. A large chunk of the remaining memory is used for buffering or caching, to compensate for slow memory cards during recording or review.
By the way, I recently bought 2GB DDR2 memory for about 32 euros, anyone can stuff 32 or 64MB (DDR usually) in a camera for free. Why not do it then?

Re: Whats the memory for?
« Reply #3 on: 29 / May / 2008, 13:09:47 »
Headroom, undoubtedly.

Hiker_jon's Outline code has been added to SDM to aid stereo photography with a single camera.
A number of people have said how useful it is.
Works fine on my A620.

However, on my A460's and various other cameras, it corrupts the main menu or crashes the camera.

Can memory-allocation account for this ?


David

*

Offline DataGhost

  • ****
  • 314
  • EOS 40D, S5IS
    • DataGhost.com
Re: Whats the memory for?
« Reply #4 on: 29 / May / 2008, 14:37:24 »
I take it you check if malloc worked at all? Else you're writing in code you're not supposed to touch. If the malloc checks return a non-null address, it shouldn't corrupt the camera. As you can see in http://dataghost.com/chdk/drysh.txt, a clearly-defined memory pool exists and should not interfere with any code, unless you go out of bounds, of course. As you can see somewhat further down in that file (near memmap), 'system objects' live immediately after the malloc pool, so if you go out of bounds you'll overwrite system stuff which.. yeah, will probably crash the camera. If you make sure this can't happen, then I don't know why the camera crashes. Maybe the layout is different in VxWorks or something else is wrong.

Quote of relevant bits of that file:
Quote
Malloc Information
  Start Address       = 0x000db7b0
  End Address         = 0x002a4960
  Total Size          = 0x001c91b0 (  1872304)

....

0009b610 : heap start
           0x00209358(2134872)
002a4968 : DRY_HEAP_END
002a4968 : DRY_SYS_OBJS_START
           0x00007298(29336)
002abc00 : DRY_SYS_MEM_START
           0x00053000(339968)

Re: Whats the memory for?
« Reply #5 on: 29 / May / 2008, 14:49:59 »
Hi David,

As a test you might try to malloc some memory before and after the main malloc:

   if(imgbuf == 0) {
buff = malloc(10,000);
imgbuf = malloc(viewport_sizeb);
buff = malloc(10,000);
}

If this fixes the problem then there is probably a bug in the code that accesses memory outside of the imgbuf buffer.

Jon

*

Offline DataGhost

  • ****
  • 314
  • EOS 40D, S5IS
    • DataGhost.com
Re: Whats the memory for?
« Reply #6 on: 29 / May / 2008, 15:26:47 »
A few remarks...
- After allocating memory, always check that it's not null afterwards.
- Don't run malloc on the same pointer twice? -> waste of memory
- Don't use any numerical formatting... I can't check *right away* because my laptop isn't hooked up, but this *might* cause the compiler to think you're passing 2 arguments (10 and 000) and it may or may not fail. If the compiler accepts the code, that's probably the problem since you're allocating 10 bytes. Compiler errors, ignore this one
- Free your memory after using it. If you allocate too much memory and never free it, the camera might run out of memory it needs and maybe corrupt things. I should free memory in my dev build as well, but I'm not using buffers this large yet.

I don't know if this is a good general representation of your code but if it is, that's probably where your problem is.
« Last Edit: 29 / May / 2008, 15:33:29 by DataGhost »

Re: Whats the memory for?
« Reply #7 on: 29 / May / 2008, 15:36:12 »
Hi

You missed the point.  The code is just an example of what to do to test a theory:  That the bug is caused by overwriting the imgbuf memory. 

So it allocates a buffer before and after.  Not intended to be final code.  If this test code fixes the crash then it points to a bug in the real code that has to be searched for and fixed.  In this context there is no point in writing "good" code.

I didn't compile the code so didn't catch the 10,000.  It should be 10000 or any large enough number.

Jon

Re: Whats the memory for?
« Reply #8 on: 29 / May / 2008, 16:06:15 »
If this fixes the problem then there is probably a bug in the code that accesses memory outside of the imgbuf buffer.

Hi Jon.

Remember, this problem does not just apply to SDM, as reported by Jucifer it also affects the trunk build.

Re: Whats the memory for?
« Reply #9 on: 10 / June / 2008, 11:13:34 »
Also, the cameras have 32 or 64MB RAM, the 1MB set aside for malloc is just a small part of that.


Hi,
I am searching for memory to use to store viewport buffers. That way I won't need to use the heap memory for this.

For the stereo pairs routine (which is used in play mode) I thought that the raw data area might work.  I soon found that the start of the raw data gets used during play mode to decode stash the image data.

So I am using the second half of the raw data to store the viewport images (I need 2 copies).  This seems to be working, but needs more testing. Edit:  Doesn't work.  It seems that the camera uses all the ram to stash images that have been viewed.  I assume that this is so that if the user goes back then the image will be loaded faster.

It would be great to understand how the camera decodes the jpeg image and where it is stored.  Perhaps the entire image is decoded then parts are selected to send to the viewport depending on the zoom.  If we knew the format we could do all sorts of things with the jpeg images.

Or perhaps the image file is just stored in ram and the Digic processor does the decoding on the fly.

Jon
« Last Edit: 11 / June / 2008, 10:37:52 by hiker_jon »

 

Related Topics


SimplePortal © 2008-2014, SimplePortal