Teen Programmers Unite  
 

 

Return to forum top

strcpy

Posted by Talon [send private reply] at September 12, 2001, 02:40:41 PM

how would you go about making your own strcpy function in C? i mean, a function that would do the equivalent of strcpy

Posted by Talon [send private reply] at September 12, 2001, 04:00:34 PM

oh.. the reason i ask is because this prog i'm making uses alot of strcpy calls, and it's performing poorly, like almost freezing up at times (i'm pretty sure it's because of strcpy, because an earlier version without strcpy performed alot better).. basically i need a faster strcpy

Posted by taubz [send private reply] at September 12, 2001, 06:29:16 PM

I doubt you'd find a faster strcpy. AFAIK, it's a function which simply goes from the start of the string, copying byte by byte, the characters into the second string, and stopping when it sees a null.

I'd guess your performance problem is elsewhere. If it seems to freeze, then perhaps your strings are losing their terminating null characters and so each strcpy is going for a long time, and then is taking much longer than it should be?

- taubz

Posted by Talon [send private reply] at September 13, 2001, 12:18:14 AM

hmm.. well it freezes for a little bit, and unfreezes, while it processes shit (it's fine until it recieves data).. it's entirely possible it might NOT be strcpy, i suppose i should look through the code more.. i just can't think of anything else cuz i haven't changed much else... thanks

Posted by drdevil [send private reply] at September 13, 2001, 09:39:51 AM

strcpy is pretty much as optimized as it gets, even written in assembler by a competent 'optimist' (heh) wouldnt make it much faster if at all, your problem is elsewhere, poss prob taubz said.

Posted by Talon [send private reply] at September 13, 2001, 06:19:17 PM

ooook this is messed up.. it is in fact strcpy that's lagging it, i set up a test program that does a million interations of strcpy, and this is what happens.. when it's copying to a global variable, it lags like HELL! when it copies to a local variable, it doesn't have ANY lag whatsoever(and of course my program uses a good amount of global variables).. anyone know what the heck is going on and perhaps how to fix it?

Posted by taubz [send private reply] at September 14, 2001, 10:03:36 AM

Can you paste your (*short*) test program here?

Posted by Talon [send private reply] at September 14, 2001, 07:04:11 PM

erm.. forgive me for being a complete moron.. please? the 'test' program lagged because of my own idiocy, i was using an uninitialized string as the source to be copied from. i'm not really sure why it didn't lag when copying to a local variable, actually the lag is very similar to the original program lag i have, how do you determine if a string is unterminated or not?

Posted by taubz [send private reply] at September 14, 2001, 07:34:41 PM

Well... a string can go on forever in memory. You could use strlen to test to see if the length is "normal" or printf to see what strings you're dealing with. Try and figure out where you're corrupting your strings.

- taubz

Posted by drdevil [send private reply] at September 18, 2001, 01:58:10 PM

Or you could use memset to initialize the string to NULLs, and then put your stuff in there, thats what I always do, then aslong as im in the string size, it'll always be terminated.

Gaz

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.