CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Efficient copying of structures

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PaulAntonucci



Joined: 30 Dec 2003
Posts: 1
Location: Watertown, MA

View user's profile Send private message Visit poster's website

Efficient copying of structures
PostPosted: Tue Dec 30, 2003 11:17 am     Reply with quote

Hello:

I have the following problem: I need to very quickly copy a structure. I have an older version of my program which uses an 8 byte structure and a "copy" compiles nicely and efficiently as follows:


struct object_descriptor {
byte y_start;
byte y_end;
long x_up_total;
long x_down_total;
byte previous_x_up;
byte previous_x_down;
};

struct object_descriptor C1_object1, C1_object2, C2_object1, C2_object2;



.................... C2_object2 = C2_object1;
05D0: MOVF 36,W
05D1: MOVWF 3E
05D2: MOVF 37,W
05D3: MOVWF 3F
05D4: MOVF 38,W
05D5: MOVWF 40
05D6: MOVF 39,W
05D7: MOVWF 41
05D8: MOVF 3A,W
05D9: MOVWF 42
05DA: MOVF 3B,W
05DB: MOVWF 43
05DC: MOVF 3C,W
05DD: MOVWF 44
05DE: MOVF 3D,W
05DF: MOVWF 45


However, I recently expanded the data structure to 9 bytes (by adding bit fields) and the copy sets up pointers and is very time consuming as follows:

struct object_descriptor {
byte y_start;
byte y_end;
long x_up_total;
long x_down_total;
byte previous_x_up;
byte previous_x_down;
short field_index, y_start_overflow, y_end_overflow, object_started;
};


.................... C1_object2 = C1_object1;
0B32: MOVLW 2F
0B33: MOVWF 64
0B34: MOVLW 26
0B35: MOVWF 63
0B36: MOVLW 09
0B37: MOVWF 78
0B38: MOVF 63,W
0B39: MOVWF 04
0B3A: MOVF 00,W
0B3B: MOVWF 77
0B3C: MOVF 64,W
0B3D: MOVWF 04
0B3E: MOVF 77,W
0B3F: MOVWF 00
0B40: INCF 63,F
0B41: INCF 64,F
0B42: DECFSZ 78,F
0B43: GOTO 338

Do you have a solution for this problem ?

Thanks !!

Paul Antonucci
_________________
Paul Antonucci
Paul@AlbertisWindow.com
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 30, 2003 12:40 pm     Reply with quote

You may have to manually copy each element of the structure.
In terms of C code, it's messy, but it does produce the efficient
assembly code that you desire. Example:

C1_object2.y_start = C1_object1.y_start;
.
.
.
C1_object2.field_index = C1_object1.field_index;

etc.
KerryW
Guest







MEMCPY
PostPosted: Tue Dec 30, 2003 12:45 pm     Reply with quote

Try

MEMCPY(C1_object2, C1_object1, SIZEOF(C1_object1);
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 30, 2003 12:58 pm     Reply with quote

I looked at memcpy before I posted my answer.
The problem with memcpy is that it produces the same
code (with pointers) that he doesn't like.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group