Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
swapping variables
#17
Orit Wrote:What? You don't need to split anything.

Depends on programming language and its level of abstraction. It'd take a lil time to do so in LISP, for example. 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.

Orit Wrote:It's not more efficient in terms of time - either programming time or run time (although this may depend on your hardware/microcode). It is more efficient in terms of space.
Suppose each of these "variables" is a gigabyte in size. Blithely declaring a "temp" variable that can hold such a value, may swamp out your paging space and hang the computer. If you're lucky, it will only cause a "stack overrun" error, and crash your program.

But mostly this question is just an intellectual exercise.
In normal usage, one wouldn't be swapping large structures or even strings at all. One would be accessing them "by reference" ("by address", "pointers") and therefore the only thing that would need swapping is the pointers (usually an integer or two) and not the actual data.

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.

Usually, you'll use...

while I sat in class I was like "duh, I coulda just said "hi guys pointers pls""
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: