This site is no longer active and is available for archival purposes only. Registration and login is disabled.

memcpy or memmove?


memcpy or memmove?

Postby brendan » Oct 14, 2002 @ 7:38am

User avatar
brendan
pm Insider
 
Posts: 451
Joined: Oct 23, 2001 @ 2:51am
Location: Hobart, Australia


Postby cryo » Oct 14, 2002 @ 10:24am

User avatar
cryo
pm Member
 
Posts: 204
Joined: Sep 19, 2001 @ 6:01am
Location: Bonn, Germany


Postby Digby » Oct 14, 2002 @ 7:27pm

Digby
pm Insider
 
Posts: 1011
Joined: Apr 29, 2001 @ 1:53pm


Postby brendan » Oct 15, 2002 @ 12:48am

User avatar
brendan
pm Insider
 
Posts: 451
Joined: Oct 23, 2001 @ 2:51am
Location: Hobart, Australia


Postby refractor » Oct 15, 2002 @ 9:47am

From my reading, Digby meant:

"Test both ways and see which is faster rather than assuming one way is better".

(And I concur as always :)).

You want to look at circular buffers though (well, sort of circular buffers). If you always plot in one or two chunks, then you never actually have to move memory around - for your example, you just plot row 5 as one chunk then plot rows 1-4 after it... no movement of memory necessary. Just keep a record of the next row you need to zap/change.

E.g. (space denotes moving the address in the source)

12345
5 1234
45 123
345 12
2345 1
12345

No movement necessary.

(And if you're actually reading stuff from screen-memory to write it back to screen memory, performance is going to be abysmal because the screen isn't buffered or cached on most devices).

Cheers,

Ref.
User avatar
refractor
pm Insider
 
Posts: 2304
Joined: Feb 5, 2002 @ 1:12pm
Location: Luxembourg


Postby brendan » Oct 16, 2002 @ 12:22am

The buffers I'm using are not the real screen buffer, I understand what you mean about scrolling buffers, and thats what I would use, but Im introducing new data all the time e.g:

12345
23456
34567
45678
56789

etc etc (the rotated section gets drawn over, i.e where the 1 would be in line 2, gets replaced with a 6... etc.

(I could not move the rotated data that will get drawn over, but at the moment I'm leaving the funcs generic....)

-B
Last edited by brendan on Oct 16, 2002 @ 12:33am, edited 1 time in total.
User avatar
brendan
pm Insider
 
Posts: 451
Joined: Oct 23, 2001 @ 2:51am
Location: Hobart, Australia


Postby refractor » Oct 16, 2002 @ 12:29am

But if you're only moving the screen down or up then it doesn't matter if you're adding new rows... just add them where the row you've just removed was and you've still got a single buffer (if segmented) screen-sized buffer that you'll never have to move/copy in memory...
User avatar
refractor
pm Insider
 
Posts: 2304
Joined: Feb 5, 2002 @ 1:12pm
Location: Luxembourg


Postby brendan » Oct 16, 2002 @ 12:39am

smarty pants.... ;-)

that could get messy with left and right shifting as well, my brain is not up to thinking about that this early in the morning....

you would have to have an x and y offset's into the buffer.... might not be too bad as long as you can do somthing simple to work out the writing to the buffer, i.e one it gets to the end, going back to the start.....

then what about copying the said buffer to the screen buffer...? I normally use a memcpy... this would have to be replaced with a custom func to handle it!

-B
User avatar
brendan
pm Insider
 
Posts: 451
Joined: Oct 23, 2001 @ 2:51am
Location: Hobart, Australia


Postby Refractor_ » Oct 16, 2002 @ 1:33am

You're right; with X shifts involved, it gets a little messier.. but not that much. I think you'll be alright if you're plotting into your "buffer" in rows and you have an "extra" line at the end of the buffer. That way, you *still* have a contiguous block of memory to shunt into the screen memory.. well in one or two chunks anyway ;)

For the X, it's the same way of updating as the Y - you just plot to the last column(s) that went off the screen. Then you just use the offset to dump the buffer into screen memory and there's your X-Y scroller without any extraneous memcpys (and only a little bit of extra handling working on the buffer wrap-around... which is definitely faster than a large memcpy).

I'd advise getting some paper and drawing lots of pictures :) ... So long as you can start at any point and draw a full 320 pixel row you're alright. Columns are a little trickier and may need a wrap-around adding (like if(column>240) {column-=240;}).

For the sake of speed, I'd probably lose a bit of scrolling granularity on the PocketPCs and scroll 32-bits at a time = 2 pixels. The 1-2 pixel jump probably isn't all that visible and it'll be much faster plotting 32-bit chunks rather than worrying about aligning things or plotting 16-bits at a time.

Anyway, I'm sure you can work it out. I'm off to bed.

Cheers, g'night :),

Ref.
Refractor_
 


Postby angedelamort » Oct 16, 2002 @ 4:52am

User avatar
angedelamort
pm Member
 
Posts: 304
Joined: Mar 7, 2002 @ 11:16pm
Location: Montreal, Quebec


Postby Digby » Oct 16, 2002 @ 7:25am

Digby
pm Insider
 
Posts: 1011
Joined: Apr 29, 2001 @ 1:53pm


Postby brendan » Oct 16, 2002 @ 7:51am

Atm speed is not a "huge" factor, and my "game" is pushing good frame rates on my e-125, I suspect it may only be an arm game in the end but. Once I add music, sound and the final touches, it's bound to slow it down..... (beside this game is just a "quickie".... (see other post on random 2D Platform generation)

-B
User avatar
brendan
pm Insider
 
Posts: 451
Joined: Oct 23, 2001 @ 2:51am
Location: Hobart, Australia


Postby refractor » Oct 16, 2002 @ 8:00am

Brendan - there's never a real excuse for not doing it "properly", IMHO :P

AngelDeLaMort - sounds weird. I can understand 32-bit being slower if you gave memcpy a non-32bit-aligned source/destination... but other than that it should be faster. Post the assembler if you want and we can ogle it. :)

Cheers,

Ref.
User avatar
refractor
pm Insider
 
Posts: 2304
Joined: Feb 5, 2002 @ 1:12pm
Location: Luxembourg


Postby angedelamort » Oct 16, 2002 @ 5:03pm

User avatar
angedelamort
pm Member
 
Posts: 304
Joined: Mar 7, 2002 @ 11:16pm
Location: Montreal, Quebec


Return to Windows Mobile


Sort


Forum Description

A discussion forum for mobile device developers on the Windows Mobile platform. Any platform specific topics are welcome.

Moderators:

Dan East, sponge, Digby, David Horn, Kevin Gelso, RICoder

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum