??? 09/28/04 14:07 Read: times |
#78297 - RE: Copying structures Responding to: ???'s previous message |
For:
typedef struct s { unsigned char bytes[5]; } myStruct; myStruct volume_disp; myStruct counted_pulses; volume_disp = counted_pulses; // efficiently copies the data! Keil C51 will simply make a call to memcpy(). memcpy() is designed for speed, but it is a big function. If you are short of code space, this can be a problem. You can code "direct" copies or write your own copy function that will be much more compact than a single instance of memcpy(). However, memcpy() has a way of getting into C51 programs even when the application does not make explicit use of it. For example, it will be called to initialise a structure or an array. If it is there, you might as well use it. It is a pity that Keil does not offer the option of a slow, but compact memcpy() for use in projects with little code space. A compact memcpy() is very easy to write but very difficult to integrate into the compiler. Keil already offer an extra fast versions of memcpy() to take advantage of multiple data pointers, it really should not be too difficult to add another optimised for size. |