Best way to disable swap in Linux

Identify configured swap devices and files with cat /proc/swaps. Turn off all swap devices and files with swapoff -a. Remove any matching reference found in /etc/fstab. Optional: Destroy any swap devices or files found in step 1 to prevent their reuse. Due to your concerns about leaking sensitive information, you may wish to consider performing … Read more

Why don’t EC2 ubuntu images have swap?

You are right, the Ubuntu EC2 EBS images don’t come with swap space configured (for 11.04 at least). The “regular” instance-type images do have a swap partition, albeit only 896 MB on the one I tested. If some process blows up and you don’t have swap space, your server could come to a crawling halt … Read more

Swapping 2 Bytes of Integer

Couple of things You can recombine by masking x with a value that is all FF except for bytes m and n You can compute the mask by left shifting 0xFF m times and n times and combining the result and then XOR it with 0xFFFFFFFF FYI when you right shift a signed value, it … Read more

How to swap String characters in Java?

Since String objects are immutable, going to a char[] via toCharArray, swapping the characters, then making a new String from char[] via the String(char[]) constructor would work. The following example swaps the first and second characters: Result:

Efficient swapping of elements of an array in Java

Nope. You could have a function to make it more concise each place you use it, but in the end, the work done would be the same (plus the overhead of the function call, until/unless HotSpot moved it inline — to help it with that, make the function static final).

Python Array Rotation

So I am implementing a block swap algorithm in python. The algorithm I am following is this: Initialize A = arr[0..d-1] and B = arr[d..n-1] 1) Do following until size of A is equal to size of B a) If A is shorter, divide B into Bl and Br such that Br is of same … Read more