Posts

Showing posts from March, 2013

Three Optimization Tips for C++ - by Andrei Alexandrescu

Image
This is an approximate transcript of my talk at Facebook NYC on December 4, 2012, which discusses optimization tips for C++ programs. The video of the talk is  here  and the accompanying slides are  here . Scope Commonly given advice about approaching optimization in general, and optimization of C++ code in particular, includes: Quoting Knuth more or less out of context The classic one-two punch: (a) Don't do it; (b) Don't do it yet Focus on algorithms, not on micro-optimization Most programs are I/O bound Avoid constructing objects unnecessarily Use C++11's rvalue references to implement move constructors That's great advice, save for two issues. First, it has becomed hackneyed by overuse and is often wielded to dogmatically smother new discussions before they even happen. Second, some of it is vague. For example, "choose the right algorithm" is vacuous without a good understanding of what algorithms are best supported by the computing fabri...

Retrieving IP address of each Interface through MAC address for a host machine

public static void main(String args[]) throws Exception { System.out.println(getIPFromMac("54DE06EA540A")); } /** * @param macAddress *            should be in byte format without non-numeric values *            eg:0123456789AB * @return * @throws SocketException */ static String getIPFromMac(String macAddress) throws SocketException { Enumeration netintfaces = java.net.NetworkInterface .getNetworkInterfaces(); HashMap macIpMapper = new HashMap (); while (netintfaces.hasMoreElements()) { try { NetworkInterface ninterfaces = netintfaces.nextElement(); String mac = DatatypeConverter.printHexBinary((ninterfaces .getHardwareAddress())); Enumeration netIpaddresses = ninterfaces .getInetAddresses(); while (netIpaddresses.hasMoreElements()) { try { InetAddress ip = netIpaddresses.nextElement(); String ipStr = ip.getHostAddress(); ...