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 <cstring> | |
#include <iostream> | |
char buf[256]; | |
size_t idx = 0; | |
void *malloc(size_t size) { | |
void* res = &buf[idx]; | |
memset(res, 0xFF, size); | |
idx += size; |
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
all: | |
g++ -o main.o -c main.cpp | |
g++ -o global_object_glog_test main.o -lglog -pthread | |
clean: | |
rm -rf global_object_glog_test | |
rm -rf *.o |
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 <algorithm> | |
#include <iostream> | |
using namespace std; | |
struct Num { | |
int n[9]; | |
int cnt; | |
Num() { | |
for (int i = 0; i < 9; i++) |
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 <iostream> | |
int reverse_digit(int n) { | |
int res = 0; | |
while (n != 0) { | |
res = res * 10 + (n % 10); | |
n /= 10; | |
} | |
return res; | |
} |
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 <algorithm> | |
#include <thread> | |
#include <glog/logging.h> | |
using namespace std; | |
volatile uint64_t g_value; | |
void write_proc() { | |
constexpr int CNT = 1000000; |
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 <iostream> | |
int main() | |
{ | |
{ | |
// float to int | |
float f = 1; | |
int i = *((int*)&f); | |
std::cout << i << std::endl; | |
} |
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 <assert.h> // for assert | |
#include <iostream> // for std::cout | |
#include <climits> // for INT_MAX | |
int get_third_largest_number(int* arr, int n) | |
{ | |
int max1 = -INT_MAX; | |
int max2; | |
int max3; |
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 <iostream> | |
unsigned __attribute__ ((noinline)) f(unsigned a) | |
{ | |
return a/9; | |
.cfi_startproc | |
movl %edi, %eax | |
movl $954437177, %edx | |
mull %edx | |
shrl %edx |
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 <map> | |
#include <cstdlib> | |
#include <iostream> | |
#include <string.h> | |
#include <VPerformanceElapsedTimer> | |
struct Key1 | |
{ | |
int a; | |
int b; |
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
SOURCES = main.cpp | |
OBJECTS = $(SOURCES:.cpp=.o) | |
EXECUTABLE = $(shell basename $(PWD)) | |
LDFLAGS += -lpthread | |
all: $(SOURCES) $(EXECUTABLE) | |
$(EXECUTABLE): $(OBJECTS) | |
$(CXX) -o $@ $(OBJECTS) $(LDFLAGS) |