<dependency>
<groupId>com.jhlabs</groupId>
<artifactId>filters</artifactId>
<version>2.0.235</version>
</dependency>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.image.BufferedImage; | |
import java.io.ByteArrayInputStream; | |
import java.io.ByteArrayOutputStream; | |
import java.io.File; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import javax.imageio.ImageIO; | |
public class ReadBufferedImageFromByte { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* int | |
* inet_pton4(src, dst) | |
* like inet_aton() but without all the hexadecimal and shorthand. | |
* return: | |
* 1 if `src' is a valid dotted quad, else 0. | |
* notice: | |
* does not touch `dst' unless it's returning 1. | |
* author: | |
* Paul Vixie, 1996. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* From openssh4.3p2 compat/inet_aton.c */ | |
/* | |
* Copyright (c) 1983, 1990, 1993 | |
* The Regents of the University of California. All rights reserved. | |
* | |
* Redistribution and use in source and binary forms, with or without | |
* modification, are permitted provided that the following conditions | |
* are met: | |
* 1. Redistributions of source code must retain the above copyright | |
* notice, this list of conditions and the following disclaimer. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#include <stdio.h> | |
#include <cassert> | |
static __inline int isdigit(char c) | |
{ | |
return c >= '0' && c <= '9'; | |
} | |
int aton(const char* ip, int* inet_addr) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <unistd.h> | |
#define ONE_MB (1024 * 1024) | |
int main() | |
{ | |
printf("The number of processors configured is :%ld\n", | |
sysconf(_SC_NPROCESSORS_CONF)); | |
printf("The number of processors currently online (available) is :%ld\n", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <linux/module.h> | |
#include <linux/kernel.h> | |
#include <linux/init.h> | |
#include <linux/hardirq.h> | |
#include <linux/preempt.h> | |
#include <linux/sched.h> | |
#include <linux/slab.h> | |
#define SIZE_OF_STAT 100000 | |
#define BOUND_OF_LOOP 1000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdint> | |
#include <iostream> | |
//#include <linux/preempt.h> | |
__attribute__((always_inline)) uint64_t perf_counter(void) | |
{ | |
uint32_t lo, hi; | |
// take time stamp counter, rdtscp does serialize by itself, and is much cheaper than using CPUID | |
__asm__ __volatile__ ( | |
"rdtscp" : "=a"(lo), "=d"(hi) |
In my time at Headlands Technologies, I’ve gotten the opportunity to build some utilities that have improved the ergonomics of maintaining high-performance C++ codebases. This article will give a generic overview of one of those utilities, OutOfLine.
Let’s start with a motivating example. Suppose you have a system that opens a very large number of paths. Maybe they are files, maybe they are named UNIX sockets, maybe pipes. But for whatever reason, you open a lot of file descriptors at startup, then you do a lot of processing on those descriptors, and finally when you’re done you close the descriptors and unlink the paths.
An (abbreviated) initial design might look like this:
class UnlinkingFD {
std::string path;
public:
int fd;
OlderNewer