Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
swapping variables
#18
Devil's Sunrise Wrote:Depends on programming language and its level of abstraction. It'd take a lil time to do so in LISP, for example.

Yeah, well, if you're writing in LISP, efficiency (in time and/or space) is obviously not a priority.

In general, if you're writing in a high-level language, you trust your compiler to do whatever optimizations are necessary.

As I said before, the question at the start of the thread is mostly an intellectual exercise. A riddle.

Quote: I knew that it's possible to work with ASM in C#, but I've never really worked with it, so kill me on this one. heh.

What I wrote above wasn't ASM. It's pure C. I don't know C#, only C and C++, so I don't know whether C# has disabled such "careless" use of pointers. I wouldn't be surprised, though.

Quote:I checked speed of x0ring and temporarily value now, For 2^31-1 swappings, you'll use 1.7%-1.3% less time with temp. value.

On your processor (Intel?).
There are others where you'd use 100% more time using XOR. But the idea is to save space, not time.

Quote:Usually, you'll use...

while I sat in class I was like "duh, I coulda just said "hi guys pointers pls""

Unless, of course, the two data to be swapped reside in different address spaces. Possibly even on different machines.
Reply


Messages In This Thread
swapping variables - by GummyBear - 2008-10-24, 02:58 AM
swapping variables - by loddlaen - 2008-10-24, 03:02 AM
swapping variables - by Fiel - 2008-10-24, 03:05 AM
swapping variables - by Stereo - 2008-10-24, 09:32 AM
swapping variables - by GummyBear - 2008-10-27, 12:29 AM
swapping variables - by Horusmaster - 2008-10-27, 12:39 AM
swapping variables - by Russt - 2008-10-27, 01:36 AM
swapping variables - by Horusmaster - 2008-10-27, 02:00 AM
swapping variables - by Russt - 2008-10-27, 02:02 AM
swapping variables - by Horusmaster - 2008-10-27, 02:07 AM
swapping variables - by Nikkey - 2008-10-27, 02:15 AM
swapping variables - by Russt - 2008-10-27, 02:21 AM
swapping variables - by Orit - 2008-10-27, 02:54 AM
swapping variables - by Nikkey - 2008-10-27, 04:51 AM
swapping variables - by Stereo - 2008-10-27, 07:53 AM
swapping variables - by Orit - 2008-10-27, 09:21 AM
swapping variables - by Nikkey - 2008-10-27, 10:17 AM
swapping variables - by Orit - 2008-10-27, 10:49 AM
swapping variables - by Nikkey - 2008-10-27, 11:59 AM
swapping variables - by Devil - 2008-10-27, 12:03 PM
swapping variables - by Orit - 2008-10-27, 12:18 PM
swapping variables - by Nikkey - 2008-10-27, 12:18 PM
swapping variables - by GummyBear - 2008-10-27, 07:33 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)