- 博客(23)
- 资源 (14)
- 收藏
- 关注
原创 异步asio udp server和client (单线程)
1.asyn_asio_udp_server.hpp#ifndef ASYN_ASIO_UDP_SERVER_HPP_#define ASYN_ASIO_UDP_SERVER_HPP_#include <string.h>#include <iostream>#include <string>#include "boost/asio.hpp"...
2019-07-07 14:06:50 1225 1
原创 测试系统堆内存
一 需求:使用new操作测试程序最多可申请多大的堆内存二 实现:1.直接使用new直接使用new可能会抛出bad_alloc异常,所以要使用try catch捕获2.使用new(nothrow)分配失败不会抛出异常,而是返回空指针三 代码:1.test.cpp#include <stdint.h>#include <iostream>...
2019-07-04 15:43:33 285
原创 redis client pool
1.redis_client.hpp#ifndef REDIS_CLIENT_HPP_#define REDIS_CLIENT_HPP_#include <hiredis/hiredis.h>#include <string.h>#include <iostream>#include <string>using namespace ...
2019-07-03 21:01:53 748
原创 程序性能优化---倒置字符串中单词
需求:输入 have a nice day输出 day nice a have实现:#include <unistd.h>#include <iostream>#include <vector>#include <sstream>#include <stack>using namespace std;stri...
2019-07-03 16:30:23 226
原创 使用select实现异步定时器
需求:实现异步定时器,不干扰其它线程实现:使用select作为超时API,但一定程度增加系统payload代码:select_timer.hpp#ifndef SRC_SELECT_TIMER_HPP_#define SRC_SELECT_TIMER_HPP_#include <sys/time.h>#include <iostream>#...
2019-07-01 18:55:52 1343
原创 CPU整数乘法能力已超越应用软件层面上的优化
一 需求:测试现代CPU整数乘法 VS 埃及乘法二 测试代码:#include <iostream>using namespace std;inline bool odd(int n) { return n & 0x01;}inline int half(int n) { return n >> 1;}inline int ...
2019-07-30 16:30:15 187
原创 likely应用
#include <stdlib.h>#include <iostream>using namespace std;#define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0)int main() { int x; cin ...
2019-07-30 15:19:35 264
原创 实时显示时间
#include <unistd.h>#include <time.h>#include <iostream>#include "select_timer.hpp"using namespace std;void show_current_time() { time_t tt = {0}; time(&tt); str...
2019-07-29 16:34:15 171
原创 c++中的委托
#ifndef SRC_COMMON_EVENTS_HPP_#define SRC_COMMON_EVENTS_HPP_#include <map>using namespace std;template <class cb_func_type>class common_events {public: common_events() { next_key...
2019-07-29 15:21:23 273
原创 string assign is not thread safe
#include <string.h>#include <time.h>#include <iostream>#include <string>#include <vector>#include <thread>#include <mutex>#include <atomic>usin...
2019-07-26 21:12:11 151
原创 元编程实现求整数序列最大值
使用元编程 stl算法库和自定义函数实现求整数序列最大值#include <stdint.h>#include <iostream>#include <vector>#include <type_traits>#include <algorithm>using namespace std;template <in...
2019-07-26 10:42:51 222
原创 元编程求阶乘
元编程求阶乘有计算优势,但必须在程序中输入常量,这个只适用特定业应用场景。#include <stdint.h>#include <iostream>#include <type_traits>using namespace std;template <unsigned n>struct factorial : std::integr...
2019-07-26 10:13:18 177
原创 simple delegate design mode
#include <iostream>using namespace std;template <class T, class R, typename... Args>class self_delegate {public: self_delegate(T *obj_ptr, R (T::*fun_ptr)(Args...)) : obj_ptr_(obj...
2019-07-25 21:04:55 118
原创 hex to decimal with two methods istringstream is so slow
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <string.h>#include <time.h>#include <iostream>#include <string>#include <sstream&g...
2019-07-24 20:41:25 156
原创 基于libevent的http server
需求:实现http server,提供rest接口实现:使用libevent实现http server,采用多线程处理,每个线程对应一个event base代码:1.socket_config.hpp#ifndef SRC_SOCKET_CONFIG_HPP_#define SRC_SOCKET_CONFIG_HPP_#include <string>using...
2019-07-24 09:40:28 760
原创 切绳子
题目描述有N条绳子,它们的长度分别为Li。如果从它们中切割出K条长度相同的绳子,这K条绳子每条最长能有多长?答案保留到小数点后2位(直接舍掉2位后的小数)。输入输出格式输入格式:第一行两个整数N和K(0<N<=10000, 0<K<=10000),接下来N行,描述了每条绳子的长度Li(0<Li<=100000.00)。输出格式:切割后每条...
2019-07-22 11:27:12 271
原创 组播例子
1.sender.cpp#include <sys/types.h> #include <sys/socket.h>#include <arpa/inet.h>#include <stdlib.h>#include <unistd.h>#include <stdio.h>#include <string...
2019-07-16 11:06:26 522
原创 random value in array
#include <stdlib.h>#include <time.h>#include <iostream>#include <string>#include <algorithm>using namespace std;void swap(int *p, int *q) { int tmp = *p; *...
2019-07-15 21:42:00 135
原创 the power of compile computation
#include <iostream>#include <string>#include <algorithm>using namespace std;template<int N>class aTMP{public: enum { ret = N * aTMP<N-1>::ret };...
2019-07-12 20:56:06 115
原创 gen similarity compute
1.similar_gen.cpp#include <string.h>#include <iostream>#include <string>#include <algorithm>#include "boost/noncopyable.hpp"using namespace std;class similar_gen : pub...
2019-07-10 21:08:04 175
原创 使用asio创建简单udp服务demo
1.server.cpp#include <iostream>#include <string>#include "boost/asio.hpp"using namespace std;using namespace boost::asio;static const size_t BUF_SIZE = 1024;int main() { io_servi...
2019-07-04 16:50:04 1133
原创 c++11以后的那些语法糖并不能带来程序性能的提升
一 需求:c++11后有些让人看着很炫的语法糖,比如tuple,for_each等,但是它们并不能提升c++程序性能,做个简单测试,验证这些语法糖带来的效果。二 实现:1.测试函数返回多个值(1)使用tuple返回 (2) 使用结构体引用返回2.测试遍历一个vector,并对其中元素执行操作 (1) 使用普通循环 (2) 使用for (auto &...
2019-07-04 14:52:19 414 1
原创 sort three number
#include <iostream>#include <set>#include <algorithm>using namespace std;void sort_three0(int &a, int &b, int &c) { vector<int>v{a, b, c}; sort(begin(v...
2019-07-01 21:18:40 182
多边形游戏
2012-01-22
字符串匹配程序
2012-01-21
计算机集群
2012-01-19
大规模并行处理机系统 MPP
2012-01-18
对称多处理机
2012-01-18
Interconnection Network
2012-01-18
Communication in Multiprocessor Systems
2012-01-18
高级计算机测试
2012-01-18
高级体系结构课程纲要
2012-01-18
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人