Blogs

CGO封装CPP库的一些最佳实践

Go
总计 4059 字
背景 最近业务上需要复用CPP编写的客户端SDK库,为了让团队主力语言Golang能够顺利接入SDK,因此使用了CGO桥接技术将C++11编写

用Go STL查询DB引发的内存泄露

Go
总计 4054 字
问题起因 这几天有一个 Go API service 经过定时监控发现占用的内存不断上涨,内存从初始的 70M 一直上升到超过 1G 直到吃光内存退出,基本上就可以断定是存在内存泄露

理解 CPU Cache 对并发性能的影响

Go
总计 461 字
一般来说每个 CPU 核有 L1 和 L2 缓存,L3是共享缓存 以缓存行为单位存储,通常是 64 字节为一行 这种利用局部性原理的缓存是数组访问比链表访问快的主要原因 伪

Go中反序列化后的类型转换问题记录

Go
总计 310 字
在 Go 语言的世界中,类型转换基本上都是很显式的,但最近在编写 web 后台的时候需要进行 context 之间的共享传值,常常就会出现 interface{} 的转换, 最常见的做法就是进行 type

Leetcode 989. Add to Array-Form of Integer

总计 252 字
题目描述 For a non-negative integer X, the array-form of X is an array of its digits in left to right order. For example, if X = 1231, then the array form is [1,2,3,1] Given the array-form A of a non-negative integer X, return the array-form of the integer X+K. // Author: Tecker // date: 2019.2.14 // 132ms, 13.3MB beat 99.19%, 100.00% // time: O(N), space: O(1) or

Leetcode 985. Sum of Even Numbers After Queries

总计 188 字
题目描述 时间复杂度:O(N) 空间复杂度:O(1) // Author: Tecker // 176ms, 28.7MB; beat 96.40%, 100% class Solution { public: vector<int> sumEvenAfterQueries(vector<int>& A, vector<vector<int> >& queries) { vector<int> res(A.size(), 0); int sum=0; A[queries[0][1]]+=queries[0][0]; for(int &num : A) { if (num%2==0) sum+=num; } res[0]=sum; for(int i=1;i<queries.size();++i) { int val=queries[i][0]; int idx=queries[i][1]; int tmp =

poj 3616 Milking Time

总计 153 字
原题地址 知识点:权值区间DP 解题报告 #include <cstdio> #include <algorithm> #include <iostream> #include <vector> using namespace std; struct P { int start, end, e; }; bool cmp(const P &a, const P &b) { return a.start < b.start; } int N, M, R; struct P a[1002]; int dp[1002]; int main() { scanf("%d %d %d", &N, &M, &R); int i,

poj 2385 Apple Catching 0ms

总计 260 字
原题地址 知识点:DP 解题报告 #include <cstdio> #include <algorithm> #include <iostream> using namespace std; // j部分定义成 31 时不行? 向前计算的时候有移动 0,..., 30次,共 31 个状态,因此要定义成 32 // d

poj 2229 Sumsets

总计 222 字
原题地址 知识点:DP 解题报告 #include <cstdio> #include <string.h> int sum; int d[1000001]; int main() { scanf("%d", &sum); int i; // 初始化唯一确定方案数,d[1] 为 1 表示 1 的分解方案只有 1 种 d[1] = 1; for(i=2;i<=sum;++i) { // 找规律,当

poj 3176 Cow Bowling

总计 96 字
原题地址 知识点:DP 解题报告 #include <cstdio> #include <algorithm> #include <iostream> using namespace std; int a[350][350]; int d[350][350]; int N; int main() { scanf("%d", &N); int i, j; for(i=0;i<N;++i) { for(j=0;j<i+1;++j) { scanf("%d", &a[i][j]); } } d[0][0] = a[0][0]; for(i=0;i<N-1;++i) { for(j=0;j<=i;++j) { // 注意这里记忆计算让重叠路径的值最大