Skip to content

Instantly share code, notes, and snippets.

@zz-jason
zz-jason / 2017-03-22.md
Created March 22, 2017 10:13
使用 gcc 的 __attribute__ 扩展来控制符号的可见性

gcc 4.0 以上的版本中支持通过 __attribute__((visibility("default"))) 来显示符号,__attribute__((visibility("hidden"))) 来隐藏符号

参考:Visibility - GCC WiKi

C++ source 文件中的 static 和 unamed namespace

在 C 中,使用 static 关键字来限制变量或者函数只能在当前文件中使用,在 C++ 中弱化了 static 的概念,取而代之的是 unamed namespace,就像下面这样:

namespace {
int sum(int a, int b) {
  return a + b;
}
}
class Utf8Iterator
{
public:
Utf8Iterator(const char* data, size_t size): mData(data), mSize(size), mPos(0) {}
~Utf8Iterator() {}
bool HasNext() const
{
return mPos < mSize;
}
@zz-jason
zz-jason / char_to_hex.h
Created March 28, 2017 06:12
convert a char to its hex representation
std::string char_to_hex(unsigned char input)
{
static const char* const dict = "0123456789ABCDEF";
std::string result("0x");
result.push_back(dict[input >> 4]);
result.push_back(dict[input & 0x0F]);
return result;
}
@zz-jason
zz-jason / sum-jit.cpp
Created June 14, 2017 03:05
example of using llvm IR library and JIT system
#include <string>
#include <iostream>
#include "llvm/ExecutionEngine/JIT.h"
#include "llvm/ADT/OwningPtr.h"
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/FileSystem.h"
@zz-jason
zz-jason / memory_manager.h
Created June 14, 2017 03:07
a memory manager copy from LevelDB
#include <assert.h>
class MemoryManager
{
public:
MemoryManager();
~MemoryManager();
char* Allocate(size_t bytes);
char* AllocateAligned(size_t bytes);
size_t GetTotal() const { return mTotal; }
@zz-jason
zz-jason / latency.txt
Created September 12, 2017 11:36 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@zz-jason
zz-jason / pool_bench_test.go
Created November 7, 2018 02:20
benchmarks of different column pool implementations
package chunk
import (
"container/list"
"sync"
"testing"
)
// implementation and benchmark of colPoolSlice.
type colPoolSlice struct {
@zz-jason
zz-jason / prompt.md
Last active January 4, 2023 05:30
prompts

bash

export PS1='\n\033[0;33m\u@10.150.180.208:\033[0;34m\w\033[0;32m$(__git_ps1 " (git:%s)") \033[0;39m\n$ '

mysql

export mysql_local = 'mysql --default-character-set=utf8 -h 127.0.0.1 -P 3306 -u root -D test --local-infile --prompt="MySQL(\\u@\\h:\\d) &gt; "'
@zz-jason
zz-jason / .vimrc
Last active January 19, 2024 06:48
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" General
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" set how many lines of history VIM has to remember
set history=1000
" enable filetype plugins
" filetype plugin on
" filetype indent on
filetype on